有没有办法使用 Uri 类在 url 中保留点段? [英] Is there a way to keep dot segments in url using Uri class?
问题描述
当我用点段创建 uri 时:
When I create a uri with dot segments:
var uri = new Uri("http://localhost/../../g");
uri 类删除了 ../
段,结果 uri 变为:
The uri class removes the ../
segments and the result uri becomes:
http://localhost/g
当点之前有路径时:
var uri = new Uri("http://localhost/a/b/c/./../../g");
// Result: http://localhost/a/g
看起来 Uri
类遵循 标准(第 33 页 - remove_dot_segments),但是有没有办法使用 Uri 类?还是我需要自定义实现?
Looks like the Uri
class is following the standart (Page 33 - remove_dot_segments), but is there any way to keep dot segments instead of automatically resolving the target uri, using Uri class? Or do I need a custom implementation?
推荐答案
如果您使用 HTTP 则不,如果您使用 Uri 类,它总是会转义它们.它对以下所有内容进行转义:file、http、https、net.pipe 和 net.tcp
If you are using HTTP then no, it will always escape them if you use the Uri class. It escapes for all of the following: file, http, https, net.pipe, and net.tcp
如果您使用的是 ftp
之类的东西,那么它不会转义,但听起来这不是您的选择.
If you are using something like ftp
then it won't escape, but it sounds like that isn't an option for you.
来自 MSDN 的文档:
作为某些方案的构造函数中规范化的一部分,转义的表示被压缩.URI 将用于的方案紧凑的转义序列包括以下内容:file、http、https、net.pipe 和 net.tcp.对于所有其他方案,转义序列是未压缩.例如:如果您将两个点.."百分比编码为"%2E%2E" 然后 URI 构造函数将压缩这个序列计划.例如,以下代码示例显示了一个 URIhttp 方案的构造函数.
As part of canonicalization in the constructor for some schemes, escaped representations are compacted. The schemes for which URI will compact escaped sequences include the following: file, http, https, net.pipe, and net.tcp. For all other schemes, escaped sequences are not compacted. For example: if you percent encode the two dots ".." as "%2E%2E" then the URI constructor will compact this sequence for some schemes. For example, the following code sample shows a URI constructor for the http scheme.
这篇关于有没有办法使用 Uri 类在 url 中保留点段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!