专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

路径中的HTTP 404或非法字符使用HttpModule重写URL时出错(HTTP 404 or Illegal characters in pat

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 0:51:45       共计:3601 浏览

	
	

我想重写我项目中的所有网址。 我是在HttpModule的帮助下完成的。 它工作正常,没有任何查询字符串。 但在某些页面中查询字符串是必不可少的 所以无法避免它。 这就是我编写HttpModule的方式。

 HttpApplication MyApp = (HttpApplication)sender;
    string MyOldPath = MyApp.Request.Path;
                switch (MyOldPath.ToLower())
                {
                    case "/profile":
                        OriginalURL = "~/Modules/UserMgmt/Users.aspx?self=true";
                        break;
                    default:
                        break;
                }
if (OriginalURL != string.Empty)
      MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty); 

当我继续这个时,我收到错误“路径中的非法字符”

然后我更新了我的webConfig,如下所示

 <system.web>
        </httpModules>
        <httpRuntime requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" requestPathInvalidCharacters="&lt;,&gt;,*,%,:,&amp;,\" />
  </system.web> 

那时“路径中的非法字符”错误解决了,并得到了Http 404错误。

调试时我可以看到当前的url,如下所示

如果我没有使用任何url重写其url,如下所示

你能帮我解决这个问题吗? 提前致谢。


I would like to rewrite all the urls in my project. I am doing it with the help of HttpModule. Its working fine without any query string. But in some pages query string is essential. So can't avoid it. This is the way I've written my HttpModule.

 HttpApplication MyApp = (HttpApplication)sender;
    string MyOldPath = MyApp.Request.Path;
                switch (MyOldPath.ToLower())
                {
                    case "/profile":
                        OriginalURL = "~/Modules/UserMgmt/Users.aspx?self=true";
                        break;
                    default:
                        break;
                }
if (OriginalURL != string.Empty)
      MyApp.Context.RewritePath(OriginalURL, string.Empty, string.Empty); 

When I proceed this I got the error " Illegal characters in path"

Then I updated my webConfig as shown below

 <system.web>
        </httpModules>
        <httpRuntime requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" requestPathInvalidCharacters="&lt;,&gt;,*,%,:,&amp;,\" />
  </system.web> 

At that time the " Illegal characters in path" error solved and getting the Http 404 Error.

I could see the current url when debugging as shown below

If I am not using any url rewrite its url as shown below

Could you help me to solve this issue. Thanks in advance.

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:c#使用正则表达式匹配字符串验证URL示例 | ·下一条:Http请求处理流程 管道流程 MVC扩展HttpModule

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有