如何从C#中的Request.UrlReferrer.AbsoluteUri中删除查询字符串部分

Man*_*ngh 7 c# query-string

我想在C#中重定向之前从Request.UrlReferrer.AbsoluteUri中删除Querystring部分.

例如,如果你有你的

Request.UrlReferrer.AbsoluteUri = "http://localhost:8080/english/index_2011.aspx?logout=true"
Run Code Online (Sandbox Code Playgroud)

现在我想

Response.Redirect(Request.UrlReferrer.AbsoluteUri) without QueryString part (?logout=true")
Run Code Online (Sandbox Code Playgroud)

请建议使用C#

Sac*_*hag 10

使用 Request.UrlReferrer.AbsoluteUri.ToString().Split('?')[0]

这应该为你做的伎俩.


Mar*_*and 9

一种更干净的方式

Request.UrlReferrer.GetLeftPart(UriPartial.Path)
Run Code Online (Sandbox Code Playgroud)

意思是我希望一切顺利.它应该回来

"http://localhost:8080/english/index_2011.aspx"
Run Code Online (Sandbox Code Playgroud)


Nei*_*ght 6

的Response.Redirect(Request.UrlReferrer.AbsoluteUri.Substring(0,Request.UrlReferrer.AbsoluteUri.IndexOf()) '?');

编辑

事实上,你实际上可以使用:

Response.Redirect(Request.UrlReferrer.AbsolutePath);
Run Code Online (Sandbox Code Playgroud)

MSDN上查看.