Home > Articles > Programming > ASP .NET

  • Print
  • + Share This
From the author of


Finally, there are a number of properties available to inspect (and potentially alter) the URL of the request that was made. The first place you should typically look for URL information is the Url property of the HttpRequest class. This property returns a reference to a class of type Uri. For each request, this property will be populated with all of the pieces of the URL of the request. In fact, although there are several other URL-related properties in the HttpRequest class, many of them are redundant with the information in the Url property. Here are most of the relevant properties of the Uri class with accompanying samples of what each property might look like:

public class Uri : MarshalByRefObject, ISerializable
{                       // sample
 public string AbsolutePath     { get; } // /foo/tst.aspx
 public string AbsoluteUri     { get; } 
                // http://www.foo.com/foo/tst.aspx?x=10
 public string Authority      { get; } // http://www.foo.com
 public string Fragment       { get; } // 
 public string Host         { get; } // http://www.foo.com
 public UriHostNameType HostNameType { get; } // Dns
 public string LocalPath      { get; } // /foo/tst.aspx
 public string PathAndQuery     { get; } // /foo/tst.aspx?x=10
 public int   Port         { get; } // 80
 public string Query        { get; } // ?x=10
 public string Scheme        { get; } // http

Several other URL-related properties are available in the HttpRequest class, as shown in the first sampling of properties and methods in Table 1. The distinctions between most of them should be obvious from the results shown in the table, with the exception of CurrentExecutionFilePath. This property returns the current path even if you have performed a server-side transfer or execute. That is, if you are processing a request made to foo.aspx and within that request perform Server.Transfer("bar.aspx") then CurrentExecutionFilePath will correctly point to bar.aspx while FilePath will still point to foo.aspx.

  • + Share This
  • 🔖 Save To Your Account