title: Get The Current Application Virtual Path in ASP.Net
body: <p>Inside the Application_Start of my Global.asax.cs, I am trying to get the current application path using:</p>
  
  <pre><code>var virtualPath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
                            + HttpRuntime.AppDomainAppVirtualPath;
  </code></pre>
  
  <p>This will return for example: <code><a href="http://localhost:99/MySite/" rel="nofollow noreferrer">http://localhost:99/MySite/</a></code></p>
  
  <p>I will then use this URL and do the following: </p>
  
  <pre><code>var pageToHit = virtualPath + Pages\MyOtherPage.aspx 
  var client = new WebClient();
  client.DownloadData(dummyPageUrl);
  </code></pre>
  
  <p>All this is fine when I run the project in IIS 6 or the Visual Studio built-in web server, however things go crazy in IIS 7 as I get a "System.Web.HttpException: Request is not available in this context".</p>
  
  <p>I am aware of this thread: <a href="https://stackoverflow.com/questions/2518057/request-is-not-available-in-this-context">Request is not available in this context</a></p>
  
  <p>However, I was wondering if anyone had any idea on how to do the above without changing the project to run in classic mode.</p>