C# How to find WCF IIS deployment/virtual directory at runtime to change name of log file?

断了今生、忘了曾经 提交于 2019-12-13 11:49:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!