Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, <code>HttpContext.Current.Request</code> and <code>Page.Request</code> are not the same. Both are instances of the same class (HttpRequest) but those are different instances.</p> <p>In each case, the private <code>HttpRequest</code> instance is created differently - I could not find the exact code creating it but keep in mind that <code>HttpContext.Current</code> is created only once, long before any Page.</p> <p>It all boils down to the following code in HttpRequest class:</p> <pre><code>public Uri Url { get { if (this._url == null &amp;&amp; this._wr != null) { string text = this.QueryStringText; if (!string.IsNullOrEmpty(text)) { text = "?" + HttpUtility.CollapsePercentUFromStringInternal(text, this.QueryStringEncoding); } if (AppSettings.UseHostHeaderForRequestUrl) { string knownRequestHeader = this._wr.GetKnownRequestHeader(28); try { if (!string.IsNullOrEmpty(knownRequestHeader)) { this._url = new Uri(string.Concat(new string[] { this._wr.GetProtocol(), "://", knownRequestHeader, this.Path, text })); } } catch (UriFormatException) { } } if (this._url == null) { string text2 = this._wr.GetServerName(); if (text2.IndexOf(':') &gt;= 0 &amp;&amp; text2[0] != '[') { text2 = "[" + text2 + "]"; } this._url = new Uri(string.Concat(new string[] { this._wr.GetProtocol(), "://", text2, ":", this._wr.GetLocalPortAsString(), this.Path, text })); } } return this._url; } } </code></pre> <p>As you can see, it first tries to read known request header (<code>GetKnownRequestHeader</code> method in <code>System.Web.HttpWorkerRequest</code> base class) and only if it fails it will invoke <code>GetServerName</code> method which will return either IP address or server name depending where the web application is hosted.</p> <p>Didn't find any official documentation or proof as to why exactly one returns IP and other the machine name, but the above can explain the difference.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload