user3483317
user3483317

Reputation: 157

Get current URL in vb.net

I am making a website in visual studio 2010 (in visual basic) and I really need to know how to get the URL from a VB statement (in the aspx.vb file, on page load).

Upvotes: 14

Views: 67713

Answers (3)

Sandeep Suthar
Sandeep Suthar

Reputation: 57

Try this.

.Html Page

 <div>
   <h1>  Url: </h1>  <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>

in .Vb Page

protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = Request.Url.ToString();

    }

Upvotes: 0

the_lotus
the_lotus

Reputation: 12748

There's a few properties that can give you the information. Here's an example.

Dim url As String = HttpContext.Current.Request.Url.AbsoluteUri
Dim path As String = HttpContext.Current.Request.Url.AbsolutePath
Dim host As String = HttpContext.Current.Request.Url.Host

Upvotes: 20

VB.NET

Imports System.Net.Dns
Imports System.Net

Dim host As String = HttpContext.Current.Request.Url.Host
Dim hostname As IPHostEntry = Dns.GetHostEntry(host)
Dim ip As IPAddress() = hostname.AddressList
Label1.Text = ip(1).ToString()

Upvotes: 0

Related Questions