URL Rewrite 导致404,500错误

匿名 (未验证) 提交于 2019-12-03 00:39:02

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.

<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

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

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