Truncating Query String & Returning Clean URL C# ASP.net

后端 未结 7 1851
遥遥无期
遥遥无期 2020-12-25 10:11

I would like to take the original URL, truncate the query string parameters, and return a cleaned up version of the URL. I would like it to occur across the whole applicatio

相关标签:
7条回答
  • 2020-12-25 10:37

    After completing whatever processing you need to do on the query string, just split the url on the question mark:

    Dim _CleanUrl as String = Request.Url.AbsoluteUri.Split("?")(0)
    Response.Redirect(_CleanUrl)
    

    Granted, my solution is in VB.NET, but I'd imagine that it could be ported over pretty easily. And since we are only looking for the first element of the split, it even "fails" gracefully when there is no querystring.

    0 讨论(0)
提交回复
热议问题