有什么方法可以在我的网站的 IIS 中获取带有应用程序名称的主机地址吗?为了清楚地说明我的问题,这里有一些我想要的例子:
http://example.com/constructionSite/myController/myAction?blah=blahh
http://example.com/tr.Implementation/myOtherController/myAction?blah=blahh
http://example.com/anotherApplication/myController/myAction?blah=blahh
http://example.com/myOtherOtherController/myAction?blah=blahh
在我的 IIS 中,我有类似上面的应用程序 constructionSite、tr.Implementation、anotherApplication、myController
。我需要获取 IIS 上带有应用程序名称的 url,换句话说,直到 myController/.....
。并且 myController
并不总是相同的 Controller ,因此我无法使用 .IndexOf()
方法。
我尝试使用 System.Web.HttpContext.Current.Request.Url.AbsoluteUri, System.Web.HttpContext.Current.Request.Url.AbsolutePath
这些路径,但它不满足我。
获取带有应用程序名称的 url 的适当方法应该是什么?
最佳答案
您可以尝试使用 Url.Content("~")
@string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"))
关于c# - 如何在.net mvc中获取带有应用程序名称的url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27101791/