码迷,mamicode.com
首页 > Web开发 > 详细

URL Rewrite 导致404,500错误

时间:2018-07-04 22:52:34      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:遇到   def   auth   bar   ati   enc   sap   exit   filter   

404 file not found,那就是rewrite的rules配的有问题,这里有篇官方文档,读完了就不会犯这种错啦。

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

 

500 server internal error,这个其实一般用ASP.NET才会遇到,尤其是MVC。。因为@Html.ActionLink之类的函数,在渲染的时候会和url rewrite冲突,报错为:

Cannot use a leading .. to exit above the top directory.

解决方法也很简单,把类似的函数用html重写下就行了,比如 

<li>@Html.ActionLink("Home", "Index", "Home")</li>

=>

<a href="/Home/Index" class="navbar-brand">Home</a>

 

还有种情况就是rewrite成功,返回了200,但是却不是自己想要的结果,如果不能正向找到问题,那就把这段配置加到system.webServer节点中去,抓去所有返回200-299的访问,然后访问下网页,再看看生成W3SVC的日志。日志生成后,记得把这段配置删了,不然会非常卡,原因你懂的。

<tracing>
  <traceFailedRequests>
    <remove path="*" />
    <add path="*">
      <traceAreas>
        <add provider="ASP" verbosity="Verbose" />
        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
        <add provider="ISAPI Extension" verbosity="Verbose" />
        <add provider="WWW Server" areas="Rewrite,RequestRouting,Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI"
       verbosity="Verbose" />
      </traceAreas>
      <failureDefinitions statusCodes="200-299" />
    </add>
  </traceFailedRequests>
</tracing>

 

下面再来一个抓访问慢的请求发生时的dump文件的配置

<tracing>
     <traceFailedRequests>
       <remove path="*" />
       <add path="*" customActionExe="d:\home\site\Diagnostics\procdump.exe" customActionParams="-ma -accepteula %1% d:\home\site\Diagnostics\w3wp_PID_%1%_" customActionTriggerLimit="5"> 
             <traceAreas>
                   <add provider="ASP" verbosity="Verbose" />
                   <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                   <add provider="ISAPI Extension" verbosity="Verbose" />
                   <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
             </traceAreas>
             <failureDefinitions timeTaken="00:00:30"  />
       </add>
     </traceFailedRequests></tracing>

 

@Html.ActionLink

URL Rewrite 导致404,500错误

标签:遇到   def   auth   bar   ati   enc   sap   exit   filter   

原文地址:https://www.cnblogs.com/nicklooo/p/9265535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!