English 中文(简体)
在登记延长监监监委的路线和地区时,监监委地区没有潜伏
原标题:MVC areas not diplaying when registering routes and areas with MVC extensions

我使用 < a href=> "http://mvcextensions.github.com/" rel="nofollow" >MVC 扩展与自动法克 < /a >, 我对自己的区域有问题。 我不知道我在做什么错。

最初,我的global.asax.cs 中有以下内容:

public class MvcApplication : AutofacMvcApplication
{
     public MvcApplication()
     {
          Bootstrapper.BootstrapperTasks
               .Include<RegisterControllers>();
     }
}

protected override void OnStart()
{
     AreaRegistration.RegisterAllAreas();

     RegisterGlobalFilters(GlobalFilters.Filters);
     RegisterRoutes(RouteTable.Routes);

     base.OnStart();
}

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
     filters.Add(new HandleErrorAttribute());
}

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 } // Parameter defaults
     );
}

有了这个代码,我的区域就展示得很好。 http://localhost:19857/dection 展示了我的索引视图。

如果我要MVC扩展程序登记我的路线和地区,那么http://localhost:19857/dection 显示的只是404个错误。

这是更新的global.asax.cs , 登记我的路线和地区:

public class MvcApplication : AutofacMvcApplication
{
     public MvcApplication()
     {
          Bootstrapper.BootstrapperTasks
               .Include<RegisterAreas>()
               .Include<RegisterControllers>()
               .Include<RegisterRoutesBootstrapperTask>();
     }

     protected override void OnStart()
     {
          RegisterGlobalFilters(GlobalFilters.Filters);

          base.OnStart();
     }

     public static void RegisterGlobalFilters(GlobalFilterCollection filters)
     {
          filters.Add(new HandleErrorAttribute());
     }
}

我的RegisterRoutesBoootstrapper Task 类 :

public class RegisterRoutesBootstrapperTask : RegisterRoutesBase
{
     public RegisterRoutesBootstrapperTask(RouteCollection routes)
          : base(routes)
     {
     }

     protected override void Register()
     {
          Routes.Clear();

          Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

          Routes.MapRoute(
               "Default",
               "{controller}/{action}/{id}",
               new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
          );
     }
}

为什么我不能展示我的区域?

<强> UPDATE

当我去http://localhost:19857/dection ,然后默认于 Dashboard 控制器索引视图。

public override string AreaName
{
     get
     {
          return "Administration";
     }
}

public override void RegisterArea(AreaRegistrationContext context)
{
     context.MapRoute(
          "Administration_default",
          "Administration/{controller}/{action}/{id}",
          new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
     );
}
最佳回答

我似乎已经解决了问题。 问题在于 < code> Routes. Clear (); I took it out and now everything is working fine. 我对上述代码所做的修改如下:

public class RegisterRoutesBootstrapperTask : RegisterRoutesBase
{
     public RegisterRoutesBootstrapperTask(RouteCollection routes)
          : base(routes)
     {
     }

     protected override void Register()
     {
          Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

          Routes.MapRoute(
               "Default",
               "{controller}/{action}/{id}",
               new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
     }
}

以下是我更新的 global.asax.cs :

public class MvcApplication : AutofacMvcApplication
{
     public MvcApplication()
     {
          Bootstrapper.BootstrapperTasks
               .Include<RegisterAreas>()
               .Include<RegisterControllers>()
               .Include<RegisterRoutesBootstrapperTask>()
               .Include<AutoMapperBootstrapperTask>();
     }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签