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
  • 18,804
  • 60
  • 181
  • 287
  • 1
    what user is the site running under? – Daniel A. White Dec 13 '12 at 00:04
  • i have my own server and have full access! – SilverLight Dec 13 '12 at 00:08
  • 1
    downvoter please give me a comment! – SilverLight Dec 13 '12 at 00:08
  • i am using default app pool = .net 4 integrated... – SilverLight Dec 13 '12 at 00:09
  • http://www.iis.net/learn/manage/configuring-security/application-pool-identities – Daniel A. White Dec 13 '12 at 00:10
  • @Moonlight downvote for "this is my code, it doesn't work". Show what you have tried. – CodeCaster Dec 13 '12 at 00:26
  • ok man, thanks for the note – SilverLight Dec 13 '12 at 00:31
  • @CodeCaster: I'm not sure I get your point. He showed what he tried, and he said he's getting string.Empty rather than a path to a desktop folder as he had expected. – Eric J. Dec 13 '12 at 00:45
  • i think he thought, i want that access for malicious jobs. but i'm not. however thanks for increasing my votes again. – SilverLight Dec 13 '12 at 01:02
  • @EricJ. and MoonLight: no I did not downvote because of malicious use of this code, I downvoted because of what I stated: there is nothing that shows _what OP has tried_. By that [we](http://www.whathaveyoutried.com) do not mean show the code, because that's not trying, that's just asking _"It doesn't work, can you fix this for me"_. Showing what you have tried is: showing you try to understand the underlying error, linking to search results for the same problem and tell the difference, quoting the manual and point out parts you don't understand, showing what you think the problem is, etc. – CodeCaster Dec 13 '12 at 07:54

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.
  • 143,945
  • 62
  • 324
  • 540
  • 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
  • 181,601
  • 45
  • 354
  • 430
  • 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