Introduction:
In this
article i am going to explain How to get current page URL/Address in asp.net
using both C# and VB.Net language.
I have
mentioned no. of ways to get the current
page URL .You can use any one as per application requirement.
In the code behind
file(.aspx.cs) write the code on page load event as:
protected
void Page_Load(object sender, EventArgs e)
{
Response.Write(Request.RawUrl); // It will print: /Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsolutePath); // It will print: /Default.aspx
Response.Write(Request.Url); // It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url); // It will print: http://localhost:4761/Default.aspx
Response.Write(Request.Url.AbsoluteUri); // It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsoluteUri); //It will print: http://localhost:4761/Default.aspx }
{
Response.Write(Request.RawUrl); // It will print: /Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsolutePath); // It will print: /Default.aspx
Response.Write(Request.Url); // It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url); // It will print: http://localhost:4761/Default.aspx
Response.Write(Request.Url.AbsoluteUri); // It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsoluteUri); //It will print: http://localhost:4761/Default.aspx }
VB.Net Code to get/read current page URL/Address in
asp.net
In the
code behind file(.aspx.vb) write the code on page load event as:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Response.Write(Request.RawUrl) ' It will print: /Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsolutePath) ' It will print: /Default.aspx
Response.Write(Request.Url) ' It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url) ' It will print: http://localhost:4761/Default.aspx
Response.Write(Request.Url.AbsoluteUri) ' It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsoluteUri) 'It will print: http://localhost:4761/Default.aspx
End Sub
Response.Write(Request.RawUrl) ' It will print: /Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsolutePath) ' It will print: /Default.aspx
Response.Write(Request.Url) ' It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url) ' It will print: http://localhost:4761/Default.aspx
Response.Write(Request.Url.AbsoluteUri) ' It will print: http://localhost:4761/Default.aspx
Response.Write(HttpContext.Current.Request.Url.AbsoluteUri) 'It will print: http://localhost:4761/Default.aspx
End Sub
0 comments:
Post a Comment