We recently had a requirement to track the initial location of our users in a Single Sign On environment.
One essential information that was needed for this requirement was to get the previous external URL from which the user came in our website.
The external URL can be very easy extracted with the following code:
if (Request.ServerVariables["HTTP_REFERER"] != null)
NOTE: If the users type the URL directly into the navigation bar of the browser, the “HTTP_REFERER” will be null regardless of the website that they currently have loaded. If fact the above code returns the external URL only in the case of a redirect from the source (hyperlink or response.redirect method).
One more thing, I also have discovered a possibility to extract markup from a page by specifying it’s URL. Below you have code to extract the title of a page by specifying it’s URL:
/// Get Page Title by URL
/// <param name="url"></param>
public string GetPage(string url)
WebRequest pageContent = WebRequest.Create(url);
WebResponse pageResponse = pageContent.GetResponse();
Stream stream = pageResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("gb2312"));
string readcontent = reader.ReadToEnd();
Match TitleMatch = Regex.Match(readcontent, "<title>([^<]*)</title>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
string pageTitle = TitleMatch.Groups.Value;