Introduction: In previous articles i explained How to create crystal reports in visual studio 2010 using asp.net and How to add meta description,meta keywords tags from code behind in asp.net(C#, VB) and How to get browser name,version,type, operating system in asp.net C#,VB.Net and Get Title,Description and Keywords Meta tags from URL in asp.net using C#, VB.Net and How to Count and display remaining characters in the multiline textbox in asp.net.
In this article i am going to explain How to get/fetch/read current page URL/Address in asp.net using both C# and VB.Net language. While working on asp.net application it is sometimes required to get the current page URL. It’s very easy. I have mentioned some ways to get the current page URL .You can use any one as per application requirement.
C#.Net Code to get/read current page URL/Address in asp.net
{
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 }
In this article i am going to explain How to get/fetch/read current page URL/Address in asp.net using both C# and VB.Net language. While working on asp.net application it is sometimes required to get the current page URL. It’s very easy. I have mentioned some 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:
{
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
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
- In the code behind file(.aspx.vb) write the code on page load event as:
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
Now over to you:
"If you like my work; you can appreciate by leaving your comments,
hitting Facebook like button, following on Google+, Twitter, Linked in and
Pinterest, stumbling my posts on stumble upon and subscribing for receiving
free updates directly to your inbox . Stay tuned and stay connected for more
technical updates."
If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..