Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Server.MapPath C#在本地工作,但不从服务器工作_C#_Server.mappath - Fatal编程技术网

Server.MapPath C#在本地工作,但不从服务器工作

Server.MapPath C#在本地工作,但不从服务器工作,c#,server.mappath,C#,Server.mappath,Server.MapPath有一个很大的问题,因为我无法从服务器上解决它,并且不确定如何测试它试图做什么 在本地,它可以以各种不同的方式正常工作,但当我将它安装到服务器上时,每个人都会失败 string filename = "TestLog.txt"; string path = Path.Combine(Server.MapPath("~/Content/"), filename); Debug.WriteLine(path) using (System.IO.StreamWriter w

Server.MapPath有一个很大的问题,因为我无法从服务器上解决它,并且不确定如何测试它试图做什么

在本地,它可以以各种不同的方式正常工作,但当我将它安装到服务器上时,每个人都会失败

string filename = "TestLog.txt";
string path = Path.Combine(Server.MapPath("~/Content/"), filename);
Debug.WriteLine(path)

using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, true))
{
    writer.WriteLine(message);
    writer.Close();
}
我在路径中尝试了/content,并在文件名中添加了额外的/。我试过使用和不使用tilda。它们都可以在本地正确解析路径,但不能在服务器上正确解析路径

作为记录,我试图访问的路径是

本地:C:\Users\username\Documents\MyWebSite\Web\Content\TestLog.txt 服务器:D:\Web\MyWebSite\Content\TestLog.txt

MyWebSite\Web是本地站点的根目录,MyWebSite是服务器上的根目录,因此MyWebSite.com/content/TestLog.txt


非常感谢您的帮助。

这将是一件非常重要的事情

当您在本地运行时(在Cassini Web服务器下…Visual Studio的一部分),您已经获得了权限

当您在IIS中托管时,可能不会

对该文件夹授予“写入”权限—所有操作都取决于您使用的IIS版本和操作方式—可能是通过应用程序池


谢谢你,伙计。给你一只肥绿色的扁虱。