How to get the base URL of a VB.NET website

I may not be the first to ask this question, but I cannot find what I was looking for after the inspection. I want to get the base url from the url. I tried

    HttpContext.Current.Request.Url.AbsoluteUri

It will return me the full URL

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

I needed only here (for example)

    http://localhost:59112/

Thank you for your help.

+5
source share
4 answers

With a little more research .. I got what I want from the forum .. this is a brilliant solution ..

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

thank

+9
source
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
0
source

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

HttpContext.Current.Request.Url.Authority

Return: "localhost: 59112"

HttpContext.Current.Request.Url.Scheme & "://" & HttpContext.Current.Request.Url.Authority

Return: " http: // localhost: 59112 "

0
source

HttpContext.Current.Request.Url.Host

-1
source

All Articles