none
Wrong path returned by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationFolder) on IIS6

    Question

  • On my test machine running (Windows XP, IIS5.1) the following code executed within a C# .NET WebService (.SVC) under a custom process identity (using machine.config to specify the user)

    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

    correctly returns

      c:\Documents and Settings\myUserName\Application Data

    However, on (Terminal Services) Windows 2003 machine running IIS6 and executing the same code but now using ApplicationPool to specify the same process identity the method returns:

    c:\Documents and Settings\Default User\Application Data

    Things I have checked while running on the TS/IIS6 machine:

    • myUserName belongs to the group IIS_WPG (even tried Admin)
    • a call to Environment.UserName correctly returns myUserName
    • a call to Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); also returns a 'Default User' path, likewise with DesktopDirectory
    • logged on as myUserName and ensured that C:\Documents and settings\myUserName exists
    • running the exact same code in a .net application on the Windows 2003 box, this works and returns the correct path.

    I am baffled, it only occurs when runing under IIS6. It is almost like it thinks that the call is coming from Network Service or Local System users and it is not checking the Identity running the Application Pool.

    Incidentally when I look at Procmon and watch a C++ application that is called from the webservice it has no such problem reading and writing to C:\Documents and settings\myUserName\ApplicatonData, it does not seem to have a problem, perhaps it builds the path differently.

    I am starting to think this might be a bug in .NET, is this possible?

    Thanks.

    Tom Deloford


     

     

     

    • Edited by tomdeloford Friday, October 15, 2010 3:01 PM Formatting
    Friday, October 15, 2010 2:57 PM

Answers

  • In IIS6 users profiles are not loaded in service process by default. I suggest  you to upgrade to IIS 7, if you can't then try call LoadUserProfile before you try to access per-user settings.

    If you have more questions about IIS's application pool behavior I suggest you to visit forums.iis.net. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Marked as answer by eryang Tuesday, October 19, 2010 6:30 AM
    Friday, October 15, 2010 4:13 PM

All replies

  • In IIS6 users profiles are not loaded in service process by default. I suggest  you to upgrade to IIS 7, if you can't then try call LoadUserProfile before you try to access per-user settings.

    If you have more questions about IIS's application pool behavior I suggest you to visit forums.iis.net. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Marked as answer by eryang Tuesday, October 19, 2010 6:30 AM
    Friday, October 15, 2010 4:13 PM
  •  

    We temporarily mark a reply, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, October 19, 2010 6:29 AM