在ASP.NET工作文件夹 [英] Working folder in ASP.NET

查看:128
本文介绍了在ASP.NET工作文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经写在ASP.NET 3.5中的Web应用程序。在这里面,我们在$ C $访问一个文件c-后面。 (普通C#文件访问,页面生命周期中的服务器上完成,这有无关的网址或网页浏览器)。

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).

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

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.

的问题是,当Web应用程序在调试模式下运行,它的工作目录既不是该项目还是溶液目录。在Windows或控制台应用程序,在项目的属性页,我可以设置工作目录。但是,在一个Web应用程序我不能。

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?

推荐答案

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

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("~");

<一个href=\"http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath/275791#275791\">This回答 给出了几个不同寻常的一个破败的使用Server.Mappath()使用也可能是有用的给你。

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

这篇关于在ASP.NET工作文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆