我可能不是第一个问这个问题的人,但我环顾四周后找不到我想要的东西。我想从 URL 获取基本 URL。我努力了
HttpContext.Current.Request.Url.AbsoluteUri
它会返回给我完整的 URL
http://localhost:59112/Resources/VideoPlayer.aspx?ID=resources1.mp4
我只需要直到这里(例如)
http://localhost:59112/
谢谢你的帮助。
我可能不是第一个问这个问题的人,但我环顾四周后找不到我想要的东西。我想从 URL 获取基本 URL。我努力了
HttpContext.Current.Request.Url.AbsoluteUri
它会返回给我完整的 URL
http://localhost:59112/Resources/VideoPlayer.aspx?ID=resources1.mp4
我只需要直到这里(例如)
http://localhost:59112/
谢谢你的帮助。
通过更多的研究..我从论坛中得到了我想要的..这是一个绝妙的解决方案..
Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath
谢谢
网址前:http://localhost:59112/Resources/VideoPlayer.aspx?ID=resources1.mp4
HttpContext.Current.Request.Url.Authority
返回:“本地主机:59112”
HttpContext.Current.Request.Url.Scheme & "://" & HttpContext.Current.Request.Url.Authority
返回:“ http://localhost:59112 ”
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim address As Uri = New Uri("http://stackoverflow.com/questions/12568530/how-to-get-the-base-url-of-the-website-vb-net")
MsgBox("http://" & address.Host)
End Sub
在 .Net 4 及更高版本中,您可以使用 -
Dim Url as String = Request.Url.OriginalString
Dim Domain as String = Url.Replace(Request.PathAndQuery, "")
Output -
Url = "http://localhost:9898/content/page.aspx
Domain = "http://localhost:9898"
HttpContext.Current.Request.Url.Host