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

前端 未结 6 433
别跟我提以往
别跟我提以往 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:23

    Try this (Haven't tried it)

    public string GetVirtualPath(string physicalPath)
    {
    string rootpath = Server.MapPath("~/");
    physicalPath = physicalPath.Replace(rootpath, "");
    physicalPath = physicalPath.Replace("\\", "/");
    return "~/" + physicalPath;
    }
    

    Link 1

    Link 2

提交回复
热议问题