Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.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
C# Server.Transfer()应该使用正斜杠还是反斜杠?_C#_Asp.net_.net_Web Applications - Fatal编程技术网

C# Server.Transfer()应该使用正斜杠还是反斜杠?

C# Server.Transfer()应该使用正斜杠还是反斜杠?,c#,asp.net,.net,web-applications,C#,Asp.net,.net,Web Applications,因为~返回带有反斜杠的路径 或: 看到使用和适合(“URL路径”)更多 我试过了,他们都成功了 那我为什么要问 因为如果您没有以正确的方式执行某项操作,它现在可能会工作,但在某个时候可能会失败,并且调试起来会非常困难。正确的使用方法是 Server.Transfer("~/Error Pages/404.aspx"); 两者都可以,但是使用/更可取,因为\内部被/取代 Server.Transfer("~/Error Pages/404.aspx"); 从.NET参考源: 调用其使用 Vi

因为~返回带有反斜杠的路径

或:

看到使用和适合(“URL路径”)更多

我试过了,他们都成功了

那我为什么要问


因为如果您没有以正确的方式执行某项操作,它现在可能会工作,但在某个时候可能会失败,并且调试起来会非常困难。

正确的使用方法是

Server.Transfer("~/Error Pages/404.aspx");


两者都可以,但是使用
/
更可取,因为
\
内部被
/
取代

Server.Transfer("~/Error Pages/404.aspx");
从.NET参考源:

调用其使用
VirtualPath VirtualPath=VirtualPath.Create(路径)

此调用将
\
替换为
/

Server.Transfer("~/Error Pages/404.aspx");

值得一票,所以+1。但是,第一个只是第三方,这可能是错误的。至于第二个。已经过时了。示例不包含示例。我甚至不确定你的链接是否与此完全相同。但正如我所说+1尽管如此。谢谢。你浏览过这些吗?@gpro我知道区别。但是问题是我应该使用路径还是url路径。但是谢谢。我现在正在编辑这个问题。
internal static String FixVirtualPathSlashes(string virtualPath) 
{ 
    // Make sure we don't have any back slashes
    virtualPath = virtualPath.Replace('\\', '/');

    ...
}