开发者

Saving Files in the Root Website Directory in 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.


Try:

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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜