q987654 发表于 2017-12-28 13:44:50

runAllManagedModulesForAllRequests 和 invalid url

  有这样的经验, 在本地的 IIS 上网站运行正常,但是发布到服务器上就一堆怪怪的问题 :
  MVC routing not work
  http://stackoverflow.com/questions/12495346/asp-net-4-5-mvc-4-not-working-on-windows-server-2008-iis-7
  http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html
  Owin not work
  http://stackoverflow.com/questions/23276144/microsoft-owin-host-systemweb-and-still-getting-no-owin-environment-item-was-fou
  AuthorizeAttribute not work
  http://stackoverflow.com/questions/21170269/asp-net-mvc5-application-throwing-nullreferenceexception-when-authorizing
  http://stackoverflow.com/questions/11048863/modules-runallmanagedmodulesforallrequests-true-meaning
  Odata action 404
  等等, 这么多怪怪的问题,都可以用 runAllManagedModulesForAllRequests=”true“ 来解决.
  

<system.webServer>  
<modules runAllManagedModulesForAllRequests="true" >
  
</modules>
  
</system.webServer>
  

  但这不是个好方法. 因为性能会浪费, 还有一些静态文件的请求可能会被要求验证 (比如图片是可以含有 & 符号的, 但是你设置了这个, 就会被验证成 invalid 了).
  网上有很多替代的方案. 但是我发现在 IIS 8.5 的情况下, 基本上你只要用 vs2015 MVC template 的 webconfig 就不会遇到怪怪的问题了。
  odata action 404 则需要加一行代码在 webserver handler 里面
  

      <add name="ExtensionlessUrlHandler-Integrated-4.0Custom" path="/api*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />  

  另外提一下, IIS 使用的是 RFC 2396 对 url 进行检查
  http://www.cnblogs.com/shaomeng/p/5171178.html
  要注意图片的路径哦.
页: [1]
查看完整版本: runAllManagedModulesForAllRequests 和 invalid url