Permissions issue - can't programmatically delete files on the server

Discussion in 'ASP .Net Security' started by Rémi, Feb 7, 2006.

  1. Rémi

    Rémi Guest

    I've got a permissions issue I can't figure out; I've been searching
    for info and haven't found anything to help me.

    I'm testing an ASP.Net 2.0 application that allows a user to upload
    files, and delete them later. The upload works fine; the file gets
    saved to the proper directory. The delete does not. Here's the info:

    * * *

    Access to the path 'F:\My App\Path\SubDir\materials\' is denied.

    Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access to the
    path 'F:\Terra Cognita\Operations\Projects\IRC
    E-zine\ProjectFiles\NewWebPublisher\webInterface\ads\materials\' is

    ASP.NET is not authorized to access the requested resource. Consider
    granting access rights to the resource to the ASP.NET request identity.
    ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
    5 or Network Service on IIS 6) that is used if the application is not
    impersonating. If the application is impersonating via <identity
    impersonate="true"/>, the identity will be the anonymous user
    (typically IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET access to a file, right-click the file in Explorer,
    choose "Properties" and select the Security tab. Click "Add" to add the
    appropriate user or group. Highlight the ASP.NET account, and check the
    boxes for the desired access.

    * * *

    It's the call to System.IO.File.Delete that causes the exception.

    Seems straightforward enough. Except that when I check the folder's
    permissions in Windows Explorer (I'm testing on my local machine),
    "ASP.NET Machine Account" and "Internet Guest Account" both have full
    control on that specific directory. (I started off by giving them
    "Delete Subfolders and Files" permissions on that directory, but when
    that didn't work...)

    Can *anyone* help me figure this out? It's driving me to drink.

    Windows 2000, IIS 5.0, Microsoft .NET Framework Version:2.0.50727.42;
    ASP.NET Version:2.0.50727.42.

    Rémi, Feb 7, 2006
    1. Advertisements

  2. DKode

    DKode Guest

    that sounds like a ACL permission problem. When the file is uploaded to
    that directory, check the permissions on that file and see if they have
    the same permissions as the containing folder, if you are in a domain,
    you might try setting your identity to a domain user (just for
    testing purposes) and see if you can delete it then, also if you are
    uploading the file, ensure that you are disposing the filehandle (if
    any) because this could cause a problem as well.
    DKode, Feb 8, 2006
    1. Advertisements

  3. sChar

    sChar Guest

    Few Tips to debug
    1. Try to delete another file from the dir that dir.
    2. Check the permissions on file
    3. check the ACL permissions on the folder
    4. identity to some domain user rather than anonymous

    sChar, Feb 8, 2006
  4. sChar

    sChar Guest

    please read 1 as
    try to delete another file from that directory that is manually created.
    sChar, Feb 8, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Allen
    Scott Allen
    Jul 13, 2004
  2. Codex Twin
    Axel Dahmen
    Jan 8, 2005
  3. ARaman
    Mike Wahler
    Oct 23, 2003
  4. Curt K
    Curt K
    Nov 3, 2006
  5. Dan

Share This Page