Saturday, 13 August 2011

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;


No comments:

Post a Comment