分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

URL Rewrite 导致404,500错误

发布时间:2023-09-06 02: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.

解决方法也很简单,把类似的函数用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错误

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved