1

please see this thread :
path of desktop for current user

this code (mean path) in my local machine was ok, but after publishing returns nothing...
i mean Environment.GetFolderPath(Environment.SpecialFolder.Desktop) is empty after publish...

    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);
    //    }
    //}

what is going on and how can i fix it?

Community
  • 1
  • 1
SilverLight
  • 19,668
  • 65
  • 192
  • 300

2 Answers2

6

If the site is not running as a user with Interactive Logon privilege, there will be no desktop associated with that user.

That will typically be the case for an application pool in IIS.

It would not be wise to run the application pool with Interactive Logon because it creates a security hole.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • how can i give my web site to access server's desktop? (i have my own server) – SilverLight Dec 13 '12 at 00:12
  • 1
    @MoonLight: If you MUST write to the desktop of a particular interactive user, create a folder on the desktop and grant permissions to the app pool user to access that folder as needed. "The server" does not have a desktop, each individual user account with interactive logon privilege does. `SpecialFolders.CommonDesktopDirectory` represents desktop items that all users will see. – Eric J. Dec 13 '12 at 00:15
  • dear Eric J. i changed it's identity to administrator -> still that path is empty. i also restart iis with no help! – SilverLight Dec 13 '12 at 00:30
  • 2
    You don't want a website running as admin. You really can't use a different folder than the desktop of the server...? – CodeCaster Dec 13 '12 at 00:31
  • there are many files in my desktop that i should read and write, these files were created by a win app soft every hour. so i can not move them to www root directory. in idle of their time i want to access them. so desktop access is very important. – SilverLight Dec 13 '12 at 00:38
  • i also changed it's identity to DefaultAppPool and after that went to Desktop of administrator and add DefaultAppPool in it's security tab with full access. that path still empty!!! – SilverLight Dec 13 '12 at 00:44
  • @MoonLight: If at all possible change the windows app to write somewhere else. If there is no other option, continue to run as the current user *but grant the current user access to that path*. Since you are getting the desktop of a *different, unchanging* user you can hard-code the path to the desktop. – Eric J. Dec 13 '12 at 00:44
  • it works -> hard code the admin's desktop path + administrator as identity. now i changed administrator idenity to DefaultAppPool and give it access to that desktop. but does not work for DefaultAppPool identity... – SilverLight Dec 13 '12 at 00:57
1

Likely the app pool is running under a service account, not your personal Windows account.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • read: http://www.iis.net/learn/manage/configuring-security/application-pool-identities – Daniel A. White Dec 13 '12 at 00:11
  • 1
    @MoonLight: Don't change it to an Interactive Logon. That creates a real security hole. Instead, use a different location that is available to the app pool user. If you MUST write to the desktop of a particular interactive user, create a folder on the desktop and grant permissions to the app pool user to access that folder as needed. – Eric J. Dec 13 '12 at 00:14