ASP.NET 中的工作文件夹

发布于 2024-08-20 08:20:47 字数 396 浏览 6 评论 0原文

我们有一个用 ASP.NET 3.5 编写的 Web 应用程序。在其中,我们访问代码隐藏中的文件。 (普通的 C# 文件访问,在页面生命周期期间在服务器上完成,这与 URL 或 Web 浏览器无关)。

在我们的生产系统上,我们在 web.config 中指定相关文件的完整路径。我们希望能够在版本控制的项目中包含文件的本地副本,然后在版本控制的 web.config 中使用相对路径来指向它,以便签出的副本该应用程序可以从 Visual Studio 的调试器中运行,无需进行任何配置。

问题是,当 Web 应用程序在调试模式下运行时,其工作目录既不是项目目录,也不是解决方案目录。在 Windows 或控制台应用程序中,在项目的属性页面中,我可以设置工作目录。但在网络应用程序中我不能。

关于我如何能够完成这项工作有什么想法吗?

We have a web application written in ASP.NET 3.5. In it, we access a file in the code-behind. (Ordinary C# file access, done on the server during the page life-cycle, this has nothing to do with URLs or web browsers).

On our production systems, we specify the full path to the file in question in the web.config. We'd like to be able to include a local copy of the file in the project in version control, and then to use a relative path in the version-controlled web.config to point to it, so that a checked-out copy of the application could be run from within Visual Studio's debugger without having to do any configuration.

The problem is that when the web application is running in debug mode, its working directory is neither the project nor the solution directory. In a windows or console application, in a project's properties page I can set the working directory. But in a web application I cannot.

Any ideas on how I can manage to make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朮生 2024-08-27 08:20:47

要获取应用程序根目录的路径:

//equivalent to Server.MapPath("/"); if at domain root, e.g Http://mysite.com/
string path = Server.MapPath("~");

这个答案给出了一些不同的常见Server.MapPath()用途的概要,这些用途可能对您也有用。

To get the path of the root of the application:

//equivalent to Server.MapPath("/"); if at domain root, e.g Http://mysite.com/
string path = Server.MapPath("~");

This answer gives a rundown of a few different common Server.MapPath() uses that may also be of use to you.

独自←快乐 2024-08-27 08:20:47

在后面的代码中: HttpContext.Current.Server.MapPath("~")

In code behind: HttpContext.Current.Server.MapPath("~")

半山落雨半山空 2024-08-27 08:20:47

使用:

Server.MapPath("~");

Use:

Server.MapPath("~");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文