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

C# 在Apache的根网站目录中保存文件,c#,asp.net,apache,mod-mono,C#,Asp.net,Apache,Mod Mono,我有一个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中。 如果我向目

我有一个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"
没有任何运气。 如果临时文件夹在根目录中,我不应该使用alias,对吗

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

请尝试:

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

}