问题详情
在 ASP.NET Core 中,Request.GetDisplayUrl() 会包含查询字符串,比如请求下面的 url
https://www.cnblogs.com/dudu/tag/k8s/default.html?page=2
GetDisplayUrl 会返回和上面一模一样的的 url,而实际需要的是不带 query string 的 url
https://www.cnblogs.com/dudu/tag/k8s/default.html
请问如何实现?
回答
通过 Uri.GetLeftPart 方法解决了
var url = new Uri(Request.GetDisplayUrl()).GetLeftPart(UriPartial.Path);
版权:言论仅代表个人观点,不代表官方立场。转载请注明出处:https://www.stntk.com/question/237.html
还没有评论呢,快来抢沙发~