ASP.NET MVC Default Page

Asked

Viewed 126 times

1

Guys I have an ASP.NET MVC app with FormsAutentication and I’m having a hard time leaving a controller as home page. I have already released on web.config, but it still doesn’t work. The controller is called website, see the code:

<location path="Site">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

If I enter the full address as teste.com.br/Site works, but if you type only teste.com.br I am always directed to login page.

<authentication mode="Forms">
  <forms loginUrl="~/Permissao/Login" protection="All" slidingExpiration="false" timeout="60" cookieless="UseCookies"/>
</authentication>
<authorization>
  <deny users="?"/>
</authorization>

In my routeConfig.cs is like this:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Site", action = "Index", id = UrlParameter.Optional }
        );

But it is always directed to login page instead of Site, if I put the controller Site how Start page on the project property works, but on the hosting server does not, that is, it only works if you set up in the project property, it seems that all the rest of the project’s configuration is ignored web.config, route and etc... Someone can give a hand?

  • Your Controller is decorated with a [Authorize]?

  • In the controller "Site" I put [Allowanonymous], the strange thing is that if I put the controller as project start page it works.

1 answer

0


You have configured your project so that no Controller is accessible to those who are not logged in:

<authorization>
  <deny users="?"/>
</authorization>

Remove these lines from your web.config.

In addition, decorate the Controllers that must require login with:

[Authorize]
public class MeuController : Controller { ... }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.