1

我有一个使用 mod_mono 在 Apache 服务器上运行的 ASP.NET 应用程序。如果我在网站的根目录中有一个名为“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 上运行时的问题。

4

1 回答 1

2

尝试:

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

}
于 2010-07-16T19:59:19.690 回答