Asp.net : Get the URL (address) of current page code behind

In this article I am going to explain how to get the URL (address) of current page in asp.net code behind using C# and vb.net

Implementation:

Get Current page URL
Create a method to get the current page url.

C# code:
protected void Page_Load(object sender, EventArgs e)
    {
        GetCurrentPage();
    }
    public void GetCurrentPage()
    {
        string currentPagename = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
        lblpagename.Text = "Current page url is : "+currentPagename;
    }


VB.net code:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        GetCurrentPage()
    End Sub
    Protected Sub GetCurrentPage()
        Dim currentPagename As String = System.Web.HttpContext.Current.Request.Url.AbsoluteUri
        lblpagename.Text = "Current page url is : " + currentPagename

    End Sub

Post a Comment

0 Comments