Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I may not be the first person to ask this question but I can't find what I was looking for after looking around. I want to get base URL from the URL. I have tried

    HttpContext.Current.Request.Url.AbsoluteUri

It would return me the full URL

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

I would just need until here (e.g.)

    http://localhost:59112/

Thanks for your help.

like image 292
Laurence Avatar asked Sep 24 '12 15:09

Laurence


People also ask

How to get base URL in mvc?

How to Get the Base URL in an MVC Controller. Here's a simple one-liner to get the job done. var baseUrl = string. Format(“{0}://{1}{2}”, Request.


2 Answers

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"

like image 65
Diogo Rodrigues Avatar answered Sep 30 '22 11:09

Diogo Rodrigues


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

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

Thanks

like image 38
Laurence Avatar answered Sep 30 '22 12:09

Laurence