Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何不区分大小写比较URL?_.net_Http_String Comparison_Culture - Fatal编程技术网

.net 如何不区分大小写比较URL?

.net 如何不区分大小写比较URL?,.net,http,string-comparison,culture,.net,Http,String Comparison,Culture,我正在尝试无意识地匹配发送到ASP.NET应用程序案例的请求URL,因为机器人程序或用户可能会错误地请求非规范表单,我需要重定向它们 在语义上,哪种比较模式是最佳选择 StringComparison.OrdinalIgnoreCase StringComparison.InvariantCultureIgnoreCase StringComparison.CurrentCultureIgnoreCase Ordinal可能会受到限制,因为它进行代码点匹配。可能无法解释所有的语言差异Curre

我正在尝试无意识地匹配发送到ASP.NET应用程序案例的请求URL,因为机器人程序或用户可能会错误地请求非规范表单,我需要重定向它们

在语义上,哪种比较模式是最佳选择

StringComparison.OrdinalIgnoreCase
StringComparison.InvariantCultureIgnoreCase
StringComparison.CurrentCultureIgnoreCase
Ordinal
可能会受到限制,因为它进行代码点匹配。可能无法解释所有的语言差异
CurrentCulture
似乎不适合URL,因为URL应该不是特定于区域性的<代码>不变量文化也没有充分的意义,因为它代表了一种在地球上不存在的类似英语的文化。我不希望将其用于面向用户的字符串,甚至不希望用于浏览器中的URL


哪种模式是正确的?

正如您所指出的,没有完美的解决方案。我一直使用
InvariantCulture
,并对结果感到满意。但是,我的URL通常是英语或类似英语的,所以很难遇到问题

另一种可能是编写一个处理程序或模块来拦截请求并从HTTP头获取用户的区域性。然后,它可以利用这种文化进行转型。也许吧

这是你可以永远花在上面的事情之一。我刚刚选择了
InvariantCulture
,我想如果我遇到问题,我会重新考虑这个决定。到目前为止,还没有人注意到。至少没有人抱怨过