简体   繁体   English

替换规范URL中的Request.Url.Query值

[英]Replace Request.Url.Query value in Canonical URL

How do I replace the value of Request.Url.Query with String.Empty in the following snippet? 在以下代码段中,如何用String.Empty替换Request.Url.Query的值?

linkCanonical = "<link rel=\"Canonical\" href=\"" + Html.ViewContext.HttpContext.Request.Url + "\" />";

I know it isn't best practice. 我知道这不是最佳做法。 This is for a temporary fix. 这是一个临时解决方案。

If you want to remove the entire querystring you could use 如果要删除整个查询字符串,可以使用

Request.Url.Host + Request.Url.AbsolutePath

This takes the host and ONLY the path information 这只接受主机,只有路径信息

Using http://www.test.com/mypath.aspx?id=1 as an example it would give you www.test.com/mypath.aspx http://www.test.com/mypath.aspx?id=1为例,它将为您提供www.test.com/mypath.aspx

Here is the MSDN documentation as well to help you through the properties. 这也是MSDN文档 ,也可以帮助您了解这些属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM