« Previous Next »

Thread: System.UnauthorizedAccessException : Access to the path ... is denied.

Last post 12-20-2008 6:25 PM by Manoj Gupta. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 12-08-2008, 3:37 PM

    • dj1s
    • Not Ranked
    • Joined on 12-06-2005, 12:40 AM
    • Posts 4

    System.UnauthorizedAccessException : Access to the path ... is denied.

    I'm trying to resolve a file write issue in porting our IIS 6 / .NET 3.5 application to IIS 7. We have a temporary image directory where some server controls create images; in the past we would grant the Network Service account access to this directory and things just worked.

    Now, this fails:

    FileInfo file = new FileInfo(@"C:\approot\_images\temp\test.txt");
    if(file.Exists == false)
        file.Create();

    System.UnauthorizedAccessException : Access to the path 'C:\approot\_images\temp\test.txt' is denied.

    This _images directory is setup for anonymous access; the application is setup for Windows Authentication and impersonation is on. If I turn impersonation off the file is created successfully....

    I have the NTFS permissions for this temp directory wide-open, trying to solve the problem; so I have the IUSR account with full rights, along with IIS_IUSRS, Everyone, Network Service, Anonymous, etc... nothing I do allows the file to be created...

    Any thoughts? This all works in IIS 6... the application pool is running in Classic Mode and set to Network Service.

  • 12-15-2008, 2:00 AM In reply to

    Re: System.UnauthorizedAccessException : Access to the path ... is denied.

    How about set app pool running to Local System?

    Thanks

    Sincerely
    Microsoft Online Community Support
    Andrew Zhu - MSFT


    “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. ”
  • 12-20-2008, 6:25 PM In reply to

    Re: System.UnauthorizedAccessException : Access to the path ... is denied.

    Hi,

    Not Sure if this helps:

    8) Client impersonation is not applied in a module in the BeginRequest and AuthenticateRequest stages.
    The authenticated user is not known until the PostAuthenticateRequest stage. Therefore, ASP.NET does not impersonate the authenticated user for ASP.NET modules that run in BeginRequest and AuthenticateRequest stages. This can affect your application if you have custom modules that rely on the impersonating the client for validating access to or accessing resources in these stages.

    Workaround:
    1) Change your application to not require client impersonation in BeginRequest and AuthenticateRequest stages.

    from: http://mvolo.com/blogs/serverside/archive/2007/12/08/IIS-7.0-Breaking-Changes-ASP.NET-2.0-applications-Integrated-mode.aspx

    Rgds, Manoj Gupta
Page 1 of 1 (3 items)
Microsoft Communities