gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:02:11 29 4
gpt4 key购买 nike

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

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com