5

我正在尝试在 C# 中获取应用程序 url。我试过使用:

HttpContext.Current.Request.ApplicationPath 

但这只会返回我“/”。我正在尝试获取应用程序基本 url 的完整 url,它可能只是也可能不是“something.com”。在某些情况下,根据环境,它是“something.com/foo/bar”。

我怎样才能做到这一点?

4

2 回答 2

7

对你RawUrl来说还不够吗?

如果这给你太多,你可以试试

VirtualPathUtility.ToAbsolute("~/");
于 2013-08-05T19:20:09.023 回答
7

试试这个:

string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');
于 2013-08-05T19:20:18.187 回答