zoukankan      html  css  js  c++  java
  • Don't use runAllManagedModulesForAllRequests="true" when getting your MVC routing to work

    It seems to be common advice to make your modules section of your web.config say <modules runAllManagedModulesForAllRequests="true">. In fact this is quite a drastic thing to do to solve the routing problem and has global effects that could CAUSE ERRORS.

    You need a module that goes by the name of UrlRoutingModule-4.0 to be running through IIS. Now, since your MVC URLs are likely to end without .aspx these will not be picked up by IIS and run through the intergrated pipeline and therefore you will end up with 404 not found errors. I struggled with this when I was getting started until I found the <modules runAllManagedModulesForAllRequests="true"> workaround.

    This highly recommended fix can cause other problems. These problems come in the form of making all your registered HTTP modules run on every request, not just managed requests (e.g. .aspx). This means modules will run on ever .jpg .gif .css .html .pdf etc.

    This is:

    1. a waste of resources if this wasn't the intended use of your other modules
    2. a potential for errors from new unexpected behaviour.

    Better solution

    Fine, so the ranting about <modules runAllManagedModulesForAllRequests="true"> is over. What is a better solution?

    In the modules section of your web.config, you can add the UrlRoutingModule-4.0 module in with a blank precondition meaning it will run on all requests. You will probably need to remove it first since it is most likely already registered at machine level. So make your web.config look like this:

    1
    2
    3
    4
    5
    <modules>
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
      <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
    </modules>


    Note: the modules element does NOT contain the runAllManagedModulesForAllRequests="true" attribute because it is evil!

    http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html

  • 相关阅读:
    systabcontrol32
    winform 进程唯一,打开第二个激活第一个进程的窗体显示
    winform在 Xp下杀死进程
    安装包创建桌面快捷方式
    [最短路/线段树大法优化DIJ] 【模板】单源最短路径(标准版)
    [线段树模板题] 线段树2
    [线段树优化应用] 数星星Star
    [倍增思想/变种最短路] 跑路
    [DP/变种背包] SOFTWARE
    [前缀和/数论] 数列
  • 原文地址:https://www.cnblogs.com/RadyGo/p/6134262.html
Copyright © 2011-2022 走看看