Ich habe diese Routen:Asp.net MVC-3-Routing-Bereich nicht
Meine Website Route auf WebSite/Global.asax.cs
:
namespace WebSite
{
public class MvcApplication : HttpApplication
{
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
...
routes.MapRoute(
"Default",
"Authenticated/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "WebSite.Controllers" }
);
...
}
void Application_Start()
{
...
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
...
}
}
}
My Admin-Bereich Route auf WebSite/Areas/Admin/AdminAreaRegistration.cs
:
namespace WebSite.Areas.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"qwerty/Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "WebSite.Areas.Admin.Controllers" }
);
}
}
}
Meine URLs:
WebSite: http://www.mywebsite.com/Authenticated/Controller/Action...
Admin: http://www.mywebsite.com/qwerty/Admin/Controller/Action...
Mein Problem:
Mit WebSite URL kann ich Controller/Aktionen von Admin-Bereich aufrufen, ohne Verwendung von "QWERTY/Admin", und das ist nicht richtig. Wie kann ich das beheben?
Vielen Dank.
Möglicherweise passt Ihre Admin-Route nicht zu Ihren Controller-Aktionen, weil Sie Controller nicht in Route definiert haben. Ich meine "controller =" Home "-Aussage. –
@ Andrey.Gubal Wird das gleiche Problem, wenn ich zwei Controller mit dem gleichen Namen in der Website und Admin-Bereich habe, dadurch habe ich die Namespaces in Routen, aber nichts gelöst – Cesar