Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.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# 为什么Context.RewritePath维护查询字符串?_C#_Asp.net_Url Rewriting - Fatal编程技术网

C# 为什么Context.RewritePath维护查询字符串?

C# 为什么Context.RewritePath维护查询字符串?,c#,asp.net,url-rewriting,C#,Asp.net,Url Rewriting,在查看了下面的代码之后,我注意到对的调用在某种程度上没有丢失查询字符串,即使调用时没有查询字符串。是否有任何文档解释为什么要维护查询字符串 //URL relative path to ashx files is wrong to to path rewriting. if (Request.Url.LocalPath.EndsWith(".ashx")) { Context.RewritePath(Request.Url.LocalPath .Substring(Req

在查看了下面的代码之后,我注意到对的调用在某种程度上没有丢失查询字符串,即使调用时没有查询字符串。是否有任何文档解释为什么要维护查询字符串

//URL relative path to ashx files is wrong to to path rewriting.
if (Request.Url.LocalPath.EndsWith(".ashx")) {
    Context.RewritePath(Request.Url.LocalPath
        .Substring(Request.Url.LocalPath.LastIndexOf("/") + 1));
}

编辑:我不是在问如何解决这个问题;代码运行正常。我只是要求提供这种行为的文档。

您实际上是在重写路径,在大多数情况下,需要维护查询才能传递到新路径

例如,一个名为“getDocumentWithEnhancements.aspx”的新文档检索页面,与旧的“getDocument.aspx”相反。两者都需要一个有用的参数,但您希望使用新的参数。重写路径将完成这项工作,因为它接受传递给旧路径的查询,并传递给新路径。如果您想显示某种错误页面或其他内容,那么您可以使用重定向,或者您要重写的任何页面都将忽略查询字符串

为什么不希望通过查询?你用这个干什么?也许这不是你所需要的功能


编辑:有一个重载函数包含3个参数,其中一个是querystring,您可以将其作为null传递,以不使用querystring。

我的代码没有问题;它在做我想做的事。我只是找不到任何明确说明查询字符串得到维护的文档。如果我不传入任何查询字符串,它将使用我现有的查询字符串,因此我希望能够找到一些官方或半官方的文档,这一点在我看来并不完全明显(即,明显到足以证明不需要对其进行文档记录)。