Question

I am new to MVC and my question is this how can I setup my sites root to point to a specific Controller + Action and then in the Web.config file set the location + path of the root of the site, so eg: http://localhost:8080/ to be able to be accessed by all anonymous and logged in.

I have been playing with the location and path but just cant figure it out and in my Global.asax, I am not sure I have the right root to Home + Index as controller + Action.

Here is some code:

web.config (snippets)

<authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" timeout="2880"/>
</authentication>
<authorization>
    <deny users="?" />
    <allow users="*" />
</authorization>

I am not sure what the <location path=""> of the root of the site should be.

Global.asax (snippets)

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
           );
}

The default route in Global.asax for the site I would like it to go to the Home Controller and the Action Index, so when you type http://localhost:8080/

Thanks in advance.

Was it helpful?

Solution

You are already doing it in the third parameter of MapRoute.

new { controller = "Home", action = "Index", id = UrlParameter.Optional }

These specify your default controler and action, exactly as you want it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top