问题
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).
来源:https://stackoverflow.com/questions/3320886/c-sharp-how-to-find-wcf-iis-deployment-virtual-directory-at-runtime-to-change-na