ASP.NET: How to get URL of the current page in c#

 

Try this :
 
string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx
 
Get Application name and page name:
string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx
 
Get Application Rooth path:
string host = HttpContext.Current.Request.Url.Host;
// localhost
 
Response.Write(Request.ApplicationPath)
Address:http://localhost/basiclayout/
/basiclayout
 
Response.Write(HttpContext.Current.Request.Url.Host+Request.ApplicationPath);
 
Get Full URL:
 
Request.Url.ToString()
// http://localhost:1302/TESTERS/Default6.aspx?page=1
 
URI variable:

Uri uri= HttpContext.Current.Request.Url;


String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + “:” + uri.Port;


 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s