Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc area default page

I have a MVC 2 site with an area, let's say the area name is {Admin}

The areas and the site works fine.

What I am trying to do is to have different default page for the area.

When I am calling http://webSiteName works with no problem

but for http://webSiteName/Admin I am getting the error

The resource cannot be found

I tried it out the solutions from ASP.NET MVC 2 RC 2 returns Area-specific controller when no area specified but with no luck.

I tried also

routes.MapRoute(
                 "Admin",                                         
                 "{controller}/{action}/{id}",                               
                 new { controller = "AdminHome", action = "index" },
                 new[] { "Web.Areas.Admin.Controllers" }
                 );

and

routes.MapRoute(
                 "Admin",                                      
                 "Admin",                              
                 new { controller = "AdminHome", action = "index" },   
                 new string[] { "Web.Areas.Admin.Controllers" }
                 );

but I am still getting The resource cannot be found.

What am I doing wrong?

like image 874
profanis Avatar asked Jul 21 '10 10:07

profanis


People also ask

Is the default page in ASP.NET MVC?

In asp.net MVC the "homepage" (ie the route that displays when hitting www.foo.com) is set to Home/Index .

What is ASP area in ASP.NET MVC?

Areas are an ASP.NET feature used to organize related functionality into a group as a separate: Namespace for routing. Folder structure for views and Razor Pages.

What is the default route pattern in MVC?

The Default route maps the first segment of a URL to a controller name, the second segment of a URL to a controller action, and the third segment to a parameter named id. The Default route maps this URL to the following parameters: controller = Home. action = Index.


1 Answers

Try this. Make sure it will be in /Areas/Admin/AdminAreaRegistration.cs when your Area is named Admin.

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "AdminHome",action = "Index", id = "" }
        );
    }

You don't have to add anything to your Global.asax.

like image 185
Martin Fabik Avatar answered Sep 22 '22 13:09

Martin Fabik