Monday, 20 April 2015

ASP.NET - Current Page Url with QueryString

You might need to extract different values from url.
It might be the path or the current page or values in the querystring.
Here is a simple reference to different uri based info available to you out of the box.


Response.Write( Request.Url.Host );
Response.Write( Request.Url.AbsolutePath );
Response.Write( Request.ApplicationPath );
Response.Write( Request.Url.AbsoluteUri );
Response.Write( Request.Url.PathAndQuery );


The above sample "Request.Url" is when you use in ASP.NET Code behind.
If you use it within a class library then you will have to refer it as ""HttpContext.Current.Request.Url".

No comments:

Post a Comment