C# How to find WCF IIS deployment/virtual director

2019-03-30 09:27发布

问题:

I am trying to change the name of a c# WCF logfile based on the name of the IIS Virtual directory it is deployed to.

I tried to use the Directory.GetCurrentDirectory() call but it returns the directory c:\windows\system32\inetsrv regardless which virtual directory the WCF apps was deployed to..

So should I be looking into the VirtualDirectory Class ?? Any sample code on how to find the current Virtual Directory ?

Thanks !

回答1:

Did you try this:

string path = HostingEnvironment.MapPath("~"); 


回答2:

HostingEnvironment.ApplicationPhysicalPath

gives you the same thing as the accepted answer (in a more direct way).