问题描述
所以我有一个web项目,而我试图让网站使用C#方法的根目录 Directory.GetCurrentDirectory()
。我不希望被使用静态路径作为文件位置将被改变的未来。此方法在我imageProcess.aspx.cs文件上运行,但如果我认为这将返回:
So I have a web project, and I'm trying to get the root directory of the website using the c# method Directory.GetCurrentDirectory()
. I don't want to be using a static path as the file locations will be changing in the future. This method is running in my imageProcess.aspx.cs file, but where I thought it would return:
C:\Users\tcbl\documents\visual studio 2010\Projects\ModelMonitoring\ModelMonitoring\imageProcess.aspx.cs
我不是得到:
I'm instead getting:
C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\
任何人都可以解释为什么发生这种情况,可能是有什么可能的解决方案?非常感谢。
Can anyone explain why this is happening and what a possible solution might be? Thanks a lot.
推荐答案
当前目录是一个系统级的功能;它返回该服务器从启动目录。它无关的网站。
The current directory is a system-level feature; it returns the directory that the server was launched from. It has nothing to do with the website.
您想要 HttpRuntime.AppDomainAppPath
。
如果你在一个HTTP请求,你同样可以拨打使用Server.Mappath(〜/不管)
。
If you're in an HTTP request, you can also call Server.MapPath("~/Whatever")
.
这篇关于获取当前目录中的.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!