10

我可能不是第一个问这个问题的人,但我环顾四周后找不到我想要的东西。我想从 URL 获取基本 URL。我努力了

    HttpContext.Current.Request.Url.AbsoluteUri

它会返回给我完整的 URL

    http://localhost:59112/Resources/VideoPlayer.aspx?ID=resources1.mp4

我只需要直到这里(例如)

    http://localhost:59112/

谢谢你的帮助。

4

5 回答 5

16

通过更多的研究..我从论坛中得到了我想要的..这是一个绝妙的解决方案..

    Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath

谢谢

于 2012-09-24T16:01:28.500 回答
5

网址前: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

于 2017-03-14T12:00:40.153 回答
2
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
于 2016-09-22T02:29:21.183 回答
0

在 .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"
于 2018-04-04T19:16:41.190 回答
-1

HttpContext.Current.Request.Url.Host

于 2014-10-07T03:00:08.427 回答