c# - 如何在.net mvc中获取带有应用程序名称的url?

标签 c# asp.net-mvc url iis

有什么方法可以在我的网站的 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/

相关文章:

C#/WPF - 我无法从后台工作人员更新 UI

c# - .NET 3.5 的 Javascript : How to give textbox focus after a pop-up is closed

c# - 布局页面的下拉列表 - MVC

asp.net-mvc - 忽略 ASP .NET MVC 中的文件夹

c# - 在 C# 中使用原始套接字

c# - 如何获取从网站上传的 Excel 文件并以编程方式将数据导入 SQL Server?

asp.net-mvc - 跨站点将 DisplayFormatAttribute.ConvertEmptyStringToNull 的默认值设置为 false

java - HttpURLConnection - 在 servlet 中获取普通网站而不是移动网站

iphone - 在提交到应用商店之前,是否可以找到 iOS 应用程序的 itunes 链接?

java.io.IOException : Server returned HTTP response code: 400 for URL: