Areas not displaying in MVC 4 using MvcExtensions

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:20:18

问题


I am using ASP.NET MVC 4 RC and the latest version of MvcExtensions and MvcExtensions.Autofac.

I don't know if MVC 4 works differently to MVC 3, but my areas aren't displaying at all when using it with MvcExtensions. The code below is how I used it in my MVC 3 application. I have just copied and pasted it into my MVC 4 app. If I use the default Global.asax.cs file that came with the MVC 4 application then my areas display properly. Must this be done differently?

I replaced the Global.asax.cs file to look like this:

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

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

          base.OnStart();
     }
}

RegisterRoutesBootstrapper, AutoMapperBootstrapper and FluentValidationBootstrapper are my custom bootstrapper classes.


回答1:


I've just created a test Mvc4 app with MvcExtensions (v2.5.0) and with a custom area. Everything works fine for me.

Please make sure that you have bindingRedirects in your root web.config file:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Without these binding redirects areas will not work.



来源:https://stackoverflow.com/questions/11687840/areas-not-displaying-in-mvc-4-using-mvcextensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!