I created a web application with ASP.NET MVC3 Framework. In project,I add new area called Administrator with HomeController and Index action.
It work with
http://localhost:2813/Administrator/Home/Index
But when I try access with URL
http://localhost:2813/Home/Index
I get a error message :
Server Error in '/' Application.
The view 'Index' or its master was not found or no view engine supports the searched > > > locations. The following locations were searched: ~/Views/Home/Index.aspx ~/Views/Home/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/Home/Index.cshtml ~/Views/Home/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml
Description: An unhandled exception occurred during the execution of the current web > > > request. Please review the stack trace for more information about the error and where it > originated in the code.
I alse add namespace in maproute but it still not work. Anyone has idea? Thanks.
Update question:
This is MapRoute in Global.ascx
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Default", action = "Index", id = UrlParameter.Optional },
new[] { "SampleWebsite.Controllers" }
);
and this is AdministratorAreaRegistration.ascx
context.MapRoute(
"Administrator",
"Administrator/{controller}/{action}/{id}",
new { area = "Administrator", controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
new[] { "SampleWebsite.Areas.Administrator.Controllers" }
);
EDIT
Problem was resolved if I move MapRoute from Global to AdministratorAreaRegistration (I can not understand and explain its)
context.MapRoute(
"Administrator",
"Administrator/{controller}/{action}/{id}",
new { area = "Administrator", controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
new[] { "SampleWebsite.Areas.Administrator.Controllers" }
);
context.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { area = "", controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
namespaces: new[] { "SampleWebsite.Controllers" }
);
Now, all request to localhost/Home/Index
will be response 404 not found. Only request with exactly area name (Administrator) allowed.
Thanks for you help!