ASP.NET:HttpRequest.Url截断尾随“."人物 [英] ASP.NET: HttpRequest.Url truncates trailing '.' characters

查看:70
本文介绍了ASP.NET:HttpRequest.Url截断尾随“."人物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果到达ASP.NET应用程序的URL包含结尾的句号-.",则它们将从HttpRequest中的Url属性中被截断.

If the URL that arrives to ASP.NET application contains trailing full stops - '.', they are truncated from the Url property in HttpRequest.

例如,如果URL为" http://server/folder.../",以下调用:

For example if the URL is "http://server/folder.../", the following call:

HttpContext.Current.Request.Url.PathAndQuery;

返回"/folder/"而不是"/folder .../".

returns "/folder/" instead of "/folder.../".

尝试了解决方案,但仅在构建Uri时才有用在执行建议的代码之后,虽然可能会在执行ASP.NET Web应用程序中的任何代码之前构造HttpRequest.

Tried this solution, but it helps only if the Uri is constructed after the suggested code executes, while HttpRequest is probably constructed before any code in ASP.NET web application is executed.

关于如何保留尾随."的任何想法.在HttpRequest.Url中?

Any ideas how to preserve trailing '.' in HttpRequest.Url?

推荐答案

您可以添加

You can add the relaxedUrlToFileSystemMapping to your web.config inside <system.web> section.

  <httpRuntime relaxedUrlToFileSystemMapping="true" />

这将保留网址中的点.

但是由于某些原因, Url.PathAndQuery 不会包含点,而RawUrl会包含点.

But for some reason Url.PathAndQuery wont contain the dots, while RawUrl contains them.

HttpContext.Current.Request.Request.RawUrl;

请记住,启用 relaxedUrlToFileSystemMapping 时可能涉及一些安全隐患.

Keep in mind that there are probably some security implications when enabling relaxedUrlToFileSystemMapping.

这篇关于ASP.NET:HttpRequest.Url截断尾随“."人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆