为什么Environment.SpecialFolder.Desktop为空

Sil*_*ght 1 .net c# asp.net path windows-server-2008-r2

请参阅此主题:
当前用户的桌面路径

我的本地机器上的这段代码(平均路径)还可以,但是在发布后没有返回任何内容......
我的意思Environment.GetFolderPath(Environment.SpecialFolder.Desktop)是在发布之后是空的...

    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    Response.Write(path);
    Response.Write("<br />");
    Response.Write(Server.MapPath("/") + "myfile.htm");
    Response.Write("<br />");

    //string[] directory_list = Directory.GetDirectories(path);
    //foreach (string directory in directory_list)
    //{
    //    if (directory.Contains("blablabla"))
    //    {
    //        string sumfilePath = directory + @"\Sum.txt";
    //        Response.Write(sumfilePath);
    //    }
    //}
Run Code Online (Sandbox Code Playgroud)

发生了什么,我该如何解决?

Eri*_* J. 6

如果站点未以具有Interactive Logon权限的用户身份运行,则不会有与该用户关联的桌面.

这通常是IIS中的应用程序池的情况.

使用Interactive Logon运行应用程序池是不明智的,因为它会创建一个安全漏洞.

  • 您不希望网站以管理员身份运行.你真的不能使用与服务器桌面不同的文件夹...? (2认同)