user437291 user437291 - 1 year ago 109
ASP.NET (C#) Question

Can’t make sense of HttpRequest.ApplicationPath

returns virtual root path for current application, so shouldn’t in the following example when user requests http://localhost:64390/WebSite2/Default.aspx,
return string
, since that is the path from web site’s virtual root to
application’s virtual root? Instead it returns an empty string


<asp:Label ID="lblApplicationPath" runat="server"
Text='<%# HttpContext.Current.Request.ApplicationPath %>'>

Similarly an article at states that with browser request to, an ApplicationPath returns
, but shouldn’t it return
, since that is the path from web site’s virtual root to application’s virtual root?

Thank you

Answer Source

This depends on where the application is actually defined. In the cases described, it appears that the application is defined at the / level but the files sit in a subfolder. Your own example appears to use the built in web server to the studio. Perhaps you should configure your local IIS to serve this website and force the application root to be defined at some subfolder level other than http://localhost/.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download