Ho To Get Current Page URL,PATH,HOST NAME in Asp.Net C#

Current Page URL,PATH,HOST NAME


Current  Browser Page Url,Path,Hostname Get From TextBox Using Asp.Net C# 


                                                 DEMO

                                               


                                            
                             Download Coding

                                                   Download 

                                   HTML CODING


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="URL" />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="PATH" />
        <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="HOST" />
        <asp:Label ID="lblGET" runat="server" Font-Size="Larger" ForeColor="#CC3300" Text="Label" Width="100px"></asp:Label>       
   
    </div>
    </form>
</body>
</html>



                                   C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {       
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       lblGET.Text=HttpContext.Current.Request.Url.AbsoluteUri;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        lblGET.Text = HttpContext.Current.Request.Url.AbsolutePath;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        lblGET.Text = HttpContext.Current.Request.Url.Host;
    }
}


First - Add New Form - Add Buttons & Lable From ToolBox 





Next - Label - Call Url,Host ,Path From Current URL







Next - Run[F5] - Press Button Get The Url,Path,Hostname








0 comments:

Post a Comment