I automatic register routes for modules and trying to register routes for admin. For modules registration working fine
public class ModulSetup : BaseModule
{
public override void Setup()
{
this.SetupViewEngine();
this.SetupControllers();
}
public override void SetupRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default",
string.Empty,
new { controller = "Home", action = "Index" });
}
protected override void SetupViewEngine()
{
ViewEngines.Engines.Add(new CoreViewEngine());
}
protected override void SetupControllers()
{
ControllerBuilder.Current.DefaultNamespaces.Add("SGN.Core.Controllers");
}
}
But for admin, I get 404
public class AdminSetup : BaseModule
{
public override void Setup()
{
this.SetupViewEngine();
this.SetupControllers();
}
public override void SetupRoutes(RouteCollection routes)
{
routes.MapRoute(
"Admin",
"Admin/{controller}/{action}/{id}",
new { controller = "Site", action = "Index" });
protected override void SetupViewEngine()
{
ViewEngines.Engines.Add(new AdminViewEngine());
}
protected override void SetupControllers()
{
ControllerBuilder.Current.DefaultNamespaces.Add("SGN.Core.Admin.Controllers");
}
}
Example. I have controllers class Site
namespace SGN.Core.Admin.Controllers
{
using System.Web.Mvc;
using SGN.Framework.Controller;
public class SiteController : AdminController
{
public ActionResult Index()
{
return this.View();
}
}
}
And when I try go to http://localhost:777/Admin/Site/ server return 404 :(
UPDATE
I try create AreaAwareViewEngine ho write thee How to set a Default Route (To an Area) in MVC
But not help
UPDATE
I try use this url http://localhost:777/Admin/Site/Index work. But this not good. And Master not work.
UPDATE
I use RouteDebugger for check in other project where I use Area. What add when use Area. How I understand in DataTokens Add 3 parameters
Namespaces = SGN.Web.Areas.Admin., area = Admin, UseNamespaceFallback = False*
I try add this parameters
Namespaces = SGN.Core.Admin., area = Admin, UseNamespaceFallback = False*
But not help
UPDATE
I created the class AreaAwareViewEngine how write here How to set a Default Route (To an Area) in MVC
My class AreaRegistration
namespace SGN.Web.Admin
{
using System.Web.Mvc;
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new {area="Admin", controller = "Site", action = "Index", id = UrlParameter.Optional }
);
}
}
}
And create AdminViewEngine from AreaAwareViewEngine
namespace SGN.Core.Admin
{
using System.Web.Mvc;
using SGN.Framework;
public class AdminViewEngine : AreaAwareViewEngine
{
public AdminViewEngine()
{
AreaMasterLocationFormats = new[] { "~/Admin/Views/Shared/admin.cshtml" };
AreaPartialViewLocationFormats = new[] { "~/Admin/Views/{1}/Partials/{0}.cshtml", "~/Admin/Menu/{0}.cshtml" };
AreaViewLocationFormats = new[] { "~/Admin/Views/{1}/{0}.cshtml", "~/Admin/Menu/{0}.cshtml" };
ViewLocationFormats = AreaViewLocationFormats;
PartialViewLocationFormats = AreaPartialViewLocationFormats;
MasterLocationFormats = AreaMasterLocationFormats;
}
protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
{
return new RazorView(controllerContext, partialPath, null, false, FileExtensions);
}
protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
{
if (string.IsNullOrEmpty(masterPath))
{
masterPath = AreaMasterLocationFormats[0];
}
var view = new RazorView(controllerContext, viewPath, masterPath, true, FileExtensions);
return view;
}
}
}
Work if i go to http://localhost:777/Admin/Site/ and not work if I go to http://localhost:777/Admin