How do I get the complete virtual path of an ASP.NET application

前端 未结 6 430
别跟我提以往
别跟我提以往 2021-01-31 08:52

How do I know the the complete virtual path that my application is currently hosted? For example:

http://www.mysite.com/myApp

or



        
6条回答
  •  生来不讨喜
    2021-01-31 09:11

    The below code will solve the purpose, however you have to do a bit tuning for two types of scenarios:

    1. Hosted as separate web application.
    2. Hosted as Virtual application within a web application.

      HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpRuntime.AppDomainAppVirtualPath;

提交回复
热议问题