Thursday, 20 February 2014

Code to Get Current Page URL or Address in asp.net Using C#

In this article i will tell you how you can get the url in asp.net using c#. In this i will also tell you how to get the complete url and the page of the current url using c# in asp.net.
So here is the code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="WebApplication1.WebForm6" %>





    Code to get current page URL or Address in asp.net Using C#

   

   

        Output 1:


        Output 2:


        Output 3:


        Output 4:


        Output 5:


        Output 6:


   

   

Now out the below code in you code behind file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //For getting page name of the url
            Label1.Text = HttpContext.Current.Request.Url.AbsolutePath.ToString();

            //For getting page name in url
            Label2.Text = Request.RawUrl.ToString();

         
            //For getting complete url of address bar
            Label3.Text = HttpContext.Current.Request.Url.ToString();

            //For getting complete url of address bar
            Label4.Text = Request.Url.ToString();


            //For getting complete url of address bar
            Label5.Text = HttpContext.Current.Request.Url.AbsoluteUri.ToString();

            //For getting complete url of address bar
            Label6.Text = Request.Url.AbsoluteUri.ToString();

        }
    }
}

Now run the application.

Tags: Asp.Net , C#.Net

No comments:

Post a Comment