将文件保存在 Apache 的网站根目录中

发布于 2024-09-10 05:50:27 字数 712 浏览 7 评论 0原文

我有一个 ASP.NET 应用程序在 Apache 服务器上运行 mod_mono。 如果我在网站的根目录中有一个名为“temp”的文件夹并运行以下代码,

System.IO.TextWriter tw = new System.IO.StreamWriter("temp/test.txt");
tw.WriteLine(DateTime.Now);
tw.Close();

它将 test.txt 保存在服务器上的 C:\Program Files\Mono-2.6.4\bin\temp 中。 如果我像这样在目录名称中添加斜杠:

System.IO.TextWriter tw = new System.IO.StreamWriter("/temp/test.txt");

它将其保存到 C:/temp。两者都没有做我想做的事。

如何获取将文件保存到网站根目录内的临时文件夹的代码? 这是 mod_mono 问题还是与 Apache 有关?

我尝试将此行添加到 httpd.conf

Alias /temp "C:/Path_to_root_folder/temp"

但没有任何运气。 如果临时文件夹位于根目录中,我不必使用别名,对吗?

在我使用 XSP 作为 Web 服务器的开发环境中,一切都按预期工作。只有在 Apache 上运行时才会出现问题。

I have an ASP.NET application running on Apache server with mod_mono.
If I have a folder called "temp" located in the website's root directory and run the following code

System.IO.TextWriter tw = new System.IO.StreamWriter("temp/test.txt");
tw.WriteLine(DateTime.Now);
tw.Close();

it saves test.txt in C:\Program Files\Mono-2.6.4\bin\temp on the server.
If I add a slash to the directory name like this:

System.IO.TextWriter tw = new System.IO.StreamWriter("/temp/test.txt");

It saves it to C:/temp. Both do not do what I want.

How do I get the code to save the file to the temp folder inside my website's root directory?
Is this a mod_mono issue or something to do with Apache?

I have tried adding this line to httpd.conf

Alias /temp "C:/Path_to_root_folder/temp"

without any luck.
I shouldn't have to use alias if the temp folder is within the root directory, correct?

In my development environment which uses XSP as the web server everything works as expected. It is only a problem when running on Apache.

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

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

发布评论

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

评论(1

心如荒岛 2024-09-17 05:50:27

尝试:

string filename = Server.MapPath("~/temp/test.txt");
using (TextWriter tw = new StreamWriter(filename))
{

}

Try:

string filename = Server.MapPath("~/temp/test.txt");
using (TextWriter tw = new StreamWriter(filename))
{

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