如何从url获取当前页面,不包括查询字符串参数

问题描述 投票:2回答:1

如何获取当前页面URL,不包括查询字符串参数。我的网址就像这个https://mywebsite.com/myproject/detailspage?id=2812

我想只得到https://mywebsite.com/myproject/detailspage

我试过这个但没有帮助。

string path = HttpContext.Current.Request.Url.AbsolutePath;
string url = HttpContext.Current.Request.Url.AbsoluteUri;

请提出任何建议。

c# asp.net-mvc razor
1个回答
1
投票

Request.Url.GetLeftPart(UriPartial.Path)

© www.soinside.com 2019 - 2024. All rights reserved.