获取 .NET Web 应用程序中的当前目录 [英] Getting current directory in .NET web application
问题描述
所以我有一个 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 cbldocumentsvisual studio 2010ProjectsModelMonitoringModelMonitoringimageProcess.aspx.cs
我反而得到:
C:Program FilesCommon FilesMicrosoft SharedDevServer10.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("~/Whatever")
.
If you're in an HTTP request, you can also call Server.MapPath("~/Whatever")
.
这篇关于获取 .NET Web 应用程序中的当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!