File Access Permission Problem

Last post 04-22-2009 5:24 AM by Thomas Sun – MSFT. 11 replies.

Sort Posts:

  • File Access Permission Problem

    04-20-2009, 6:23 AM
    • Member
      17 point Member
    • ervipingupta
    • Member since 11-10-2008, 7:28 AM
    • Posts 69

     Hello FriendsCrying,

        

                 i am making uploading interface and when i upload the file i got the error which is mention below .can anyone know about this problem .

     

    Access to the path 'D:\tempzip\Book1.zip' is denied. body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

    Access to the path 'D:\tempzip\Book1.zip' 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 'D:\tempzip\Book1.zip' is denied.

    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.

    Source Error:

    Line 52:         {
    Line 53:         Directory.CreateDirectory(kl);
    Line 54:         FileUpload1.PostedFile.SaveAs(kl);
    Line 55:         tp = kl;                
    Line 56:         } 

    Filed under: , , , , , , , , , , , , , , , , , , , , , , , , , ,
  • Re: File Access Permission Problem

    04-20-2009, 7:14 AM
    • All-Star
      77,606 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 10:43 AM
    • Naples, FL, USA
    • Posts 10,552
    • Moderator
      TrustedFriends-MVPs

    Read the error message. It is your answer.

    Blatant Self Promotion: ASP.NET 3.5 CMS Development
  • Re: File Access Permission Problem

    04-20-2009, 7:47 AM
    • Member
      17 point Member
    • ervipingupta
    • Member since 11-10-2008, 7:28 AM
    • Posts 69

     hi friendCrying

       Thanks for reply but this is not answer.The folder that i make is created by my code dynamically in my C:\drive and how i give permission for writing a file in this folder.this error i face first time .

     Please help me , it is urgent

    Thanks i n advance again sir

    Vipin

  • Re: File Access Permission Problem

    04-20-2009, 7:50 AM
    • Member
      402 point Member
    • Sohan
    • Member since 11-18-2008, 9:00 AM
    • Dhaka
    • Posts 66

    If you are using Windows Server 2003, the ASP.Net account name is IIS_WPG

    In windows server 2008 it is IIS_IUSRS

    You need to allow appropriate permission (Read/Write) to this user on your folder/file.

    --
    (Please, Mark as Answer if it Helped)
    http://smsohan.blogspot.com
  • Re: File Access Permission Problem

    04-20-2009, 8:08 AM
    • Member
      17 point Member
    • ervipingupta
    • Member since 11-10-2008, 7:28 AM
    • Posts 69

     i am using windows xp.

    i have create the folder with code... how can i set permission programatically to write a file in that folder...

    what will be the code to do this

  • Re: File Access Permission Problem

    04-20-2009, 8:14 AM
    • All-Star
      26,125 point All-Star
    • qwe123kids
    • Member since 03-27-2008, 5:49 AM
    • Mumbai
    • Posts 4,446

    Hi,


    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.

    Hope it helps

    Thanks
    Avinash Tiwari

    Remember to click “Mark as Answer” on the post, if it helps you.

    MY Blog

    Hacking Inside .net exe
  • Re: File Access Permission Problem

    04-20-2009, 8:22 AM
    • Member
      17 point Member
    • ervipingupta
    • Member since 11-10-2008, 7:28 AM
    • Posts 69

     i am creating the directory at the runtime through code , and want to set the permission at the run time through code...

    how to do this

  • Re: File Access Permission Problem

    04-20-2009, 8:28 AM
    • All-Star
      77,606 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 10:43 AM
    • Naples, FL, USA
    • Posts 10,552
    • Moderator
      TrustedFriends-MVPs

    Exactly as the error message instructed.  You have to do this on the directory you are creating the dynamic directory in, not the dynamic directory, and make sure that properties are inherited by subdirectories.

    By the way, the ASP.NET account in ASPNET on XP.

    Jeff

    Blatant Self Promotion: ASP.NET 3.5 CMS Development
  • Re: File Access Permission Problem

    04-20-2009, 8:29 AM
    • All-Star
      77,606 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 10:43 AM
    • Naples, FL, USA
    • Posts 10,552
    • Moderator
      TrustedFriends-MVPs

    Sohan:

    If you are using Windows Server 2003, the ASP.Net account name is IIS_WPG

    In windows server 2008 it is IIS_IUSRS

    You need to allow appropriate permission (Read/Write) to this user on your folder/file.

    Those are not the ASP.NET accounts, those are the IIS anonymous access accounts.  And they're not used in the case of the original poster.

    Jeff

    Blatant Self Promotion: ASP.NET 3.5 CMS Development
  • Re: File Access Permission Problem

    04-20-2009, 8:47 AM
    • Member
      17 point Member
    • ervipingupta
    • Member since 11-10-2008, 7:28 AM
    • Posts 69

     how can i inherit the properties to the sub directories

  • Re: File Access Permission Problem

    04-21-2009, 3:36 AM
    • Member
      17 point Member
    • ervipingupta
    • Member since 11-10-2008, 7:28 AM
    • Posts 69

     Hello Sir,

          I am still getting same error  and i gives all write permission in IIs but my problem is not solv e.how i inherit the subdirectory .please help me .it is urgent.

    Thanks in  Advance!

    Vipin

  • Re: File Access Permission Problem

    04-22-2009, 5:24 AM
    Answer

    Hi,

    The error message indicates that ASP.NET process identity doesn't have enough permission on that folder.

    The application that is deployed on IIS is running under "ASPNET" or "NETWORK SERVICE" basing on IIS version. These accounts have low privileges.

    In this case, this folder is created at runtime, you can also set its ACL on folder. For example, you can add an ACL entry on the specified file for the specified account:

    public static void AddFileSecurity(string fileName, string account,
                FileSystemRights rights, AccessControlType controlType)
            {

                // Get a FileSecurity object that represents the
                // current security settings.
                FileSecurity fSecurity = File.GetAccessControl(fileName);

                // Add the FileSystemAccessRule to the security settings.
                fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                    rights, controlType));

                // Set the new access settings.
                File.SetAccessControl(fileName, fSecurity);

            }
     
    For more information, see http://msdn.microsoft.com/en-us/library/system.io.file.setaccesscontrol.aspx

    Note: Your application needs high permission to set ACL.

    You also can consider using Impersonation, which impersonates a specific user. So you can use impersonation to access local resources and perform operations by using the authenticated user's identity or by using a specific Windows identity.

    For more information, see How To: Use Impersonation and Delegation in ASP.NET 2.0 (http://msdn.microsoft.com/en-us/library/ms998351.aspx).

     

    I look forward to receiving your test results.

    Thomas Sun
    Microsoft Online Community Support

    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.
Page 1 of 1 (12 items)