Eug*_*ica 8 .net c# url escaping
假设我想从以下字符串创建一个Uri对象:
string url = @"http://someserver.com?param1=1&url=http%3a%2f%2fwww.otherserver.com";
Uri uri = new Uri(url, UriKind.Absolute);
Run Code Online (Sandbox Code Playgroud)
预期结果将是:
http://someserver.com?param1=1&url=http%3a%2f%2fwww.otherserver.com
Run Code Online (Sandbox Code Playgroud)
获得:
http://someserver.com/?param1=1&url=http://www.otherserver.com
Run Code Online (Sandbox Code Playgroud)
在允许创建Uri的许多相关方法中注意到相同的行为:Uri.TryCreate,UriBuilder.Uri等.
如何获得保留初始编码参数的Uri?
在.NET4中,您可以通过配置禁用某些方案的Uri压缩:
<configuration>
<uri>
<schemeSettings>
<add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
</schemeSettings>
</uri>
</configuration>
Run Code Online (Sandbox Code Playgroud)
请注意,与禁用默认行为有关的安全隐患.
您是如何“获取”URL 的?如果我在 Visual Studio 中将鼠标悬停在它上面,它确实会显示解码后的 URL。
但每当我通过该AbsoluteUri属性访问它时,它都会显示编码的 URL。