ASP.NET: HttpRequest.Url truncates trailing '.' characters

喜欢而已 提交于 2019-12-12 01:25:28

问题


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

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

HttpContext.Current.Request.Url.PathAndQuery;

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

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.

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


回答1:


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

  <httpRuntime relaxedUrlToFileSystemMapping="true" />

This will preserve the dots in the url.

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

HttpContext.Current.Request.Request.RawUrl;

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



来源:https://stackoverflow.com/questions/6804291/asp-net-httprequest-url-truncates-trailing-characters

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