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

时间:2010-07-16 19:57:31

标签: c# asp.net apache mod-mono

我有一个使用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上运行时只是一个问题。

1 个答案:

答案 0 :(得分:2)

尝试:

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

}