简体   繁体   English

IIS托管网站的网络路径

[英]Network path of a IIS hosted website

How to get the network path of a IIS hosted website in c#? 如何在C#中获取IIS托管网站的网络路径? I tried with Server.MapPath("~/") , it returns the physical path like ( C:\\inetpub\\.... ); 我尝试使用Server.MapPath("~/") ,它返回的物理路径是( C:\\inetpub\\.... ); But I want it in the form ( http://IP_Add_of_hosted_machine/Website_Name/ ). 但是我想要它的形式( http://IP_Add_of_hosted_machine/Website_Name/ )。

If you need this in Request you can use below code: 如果您在请求中需要此代码,则可以使用以下代码:

string url = HttpContext.Current.Request.Url.AbsoluteUri;
// will have something like this: http://IP_Add_of_hosted_machine/Website_Name/Default_1.aspx

If you are not in request context it is unknown for website where it is hosted. 如果您不在请求上下文中,则托管它的网站是未知的。 Moreover same directory can be hosted twice in IIS, so it will be difficult to say which one you want. 此外,同一目录可以在IIS中托管两次,因此很难说出您想要的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM