Request Url

Request Url

Some times we need to get information from Request URL. Here I will show you, what information you
can get from Request URL.

image

protected void Button1_Click(object sender, EventArgs e)
{
string fullURL = Request.Url.AbsoluteUri;
Response.Write(fullURL);
Response.Write("</br>");
string pathWithoutDomain = Request.Url.AbsolutePath;
Response.Write(pathWithoutDomain);
Response.Write("</br>");
string Filepath = Path.GetFileName(fullURL);
Response.Write(Filepath);
Response.Write("</br>");
string domain = fullURL.Replace(pathWithoutDomain, "");
Response.Write(domain);
}

Output:

http://localhost:1033/Split/Default.aspx

/Split/Default.aspx

Default.aspx

http://localhost:1033

Description
:

  1. Request.Url.AbsoluteUri
    Return fully qualified URL including protocol, domain name, directory path and
    filename with extension.
  2. Request.Url.AbsolutePath
    Returns only directory and file name with extensions. It removes domain name and protocol.
  3. To get domain name I have replaced directory and filename with blank string.
  4. The file name can be found using Path function provided in System.IO namespace.

Below code will give you website URL of site who referred your link.

Request.UrlReferrer.ToString();

It is very useful if you want to keep track of sites who uses your website links.

Tags:

RequestQueryString-and-RequestParmsHttpWebRequest Post methodhttpwebrequest web proxy[Asp.net] Get current Page URL absolute URI and query string parameters.Asp.net UrlPathEncodeAsp.net Urldecode QueryStringUrl Encode In Asp.netHttpWebRequest TimeoutHttpWebRequestHow to Pass To Query String In Asp.netAsp.net use Fully Qualified RedirectUrl

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.