Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Access is denied

Access is denied

Scheduled Pinned Locked Moved ASP.NET
asp-netcsharpdotnetsysadminwindows-admin
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wk_vigorous
    wrote on last edited by
    #1

    Hi, guys and girls I want to access a file in my ASP.net routine but it is denied. Following is the prompt information, but I don't understand it. What shold I do? Configure IIS manuslly or other things? Thanks a lot. Access to the path "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" 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 "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" 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 , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write 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 71: string filepath = EntryFilePath+@"\"+ filename; Line 72: Line 73: FileStream file = new FileStream(filepath,FileMode.Open); Line 74: Line 75: //Create a serializer Source File: c:\inetpub\wwwroot\weblog\global.asax.cs Line: 73 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 vigorous

    M 1 Reply Last reply
    0
    • W wk_vigorous

      Hi, guys and girls I want to access a file in my ASP.net routine but it is denied. Following is the prompt information, but I don't understand it. What shold I do? Configure IIS manuslly or other things? Thanks a lot. Access to the path "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" 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 "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" 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 , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write 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 71: string filepath = EntryFilePath+@"\"+ filename; Line 72: Line 73: FileStream file = new FileStream(filepath,FileMode.Open); Line 74: Line 75: //Create a serializer Source File: c:\inetpub\wwwroot\weblog\global.asax.cs Line: 73 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 vigorous

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Because you don't specify the FileAccess in the constructor, then it is given the read/write access to the file while the ASPNET account basically does not have write access, and the FileMode parameter is just used to control how a file is opened. So there are two options for you here, it depends on your requirement. If you only need to read the file contents, you then should specify the FileAccess value in the constructor like this:

      FileStream file = new FileStream(filepath,FileMode.Open, FileAccess.Read);

      If you are planning to read/write that file, you need to grant ASP.NET write access to the file.

      W 1 Reply Last reply
      0
      • M minhpc_bk

        Because you don't specify the FileAccess in the constructor, then it is given the read/write access to the file while the ASPNET account basically does not have write access, and the FileMode parameter is just used to control how a file is opened. So there are two options for you here, it depends on your requirement. If you only need to read the file contents, you then should specify the FileAccess value in the constructor like this:

        FileStream file = new FileStream(filepath,FileMode.Open, FileAccess.Read);

        If you are planning to read/write that file, you need to grant ASP.NET write access to the file.

        W Offline
        W Offline
        wk_vigorous
        wrote on last edited by
        #3

        Thank you for the advice. You are right. Now I can access the file in read mode. If I want to write it, how can I grant ASP.net the authorization? Thanks a lot vigorous

        M 1 Reply Last reply
        0
        • W wk_vigorous

          Thank you for the advice. You are right. Now I can access the file in read mode. If I want to write it, how can I grant ASP.net the authorization? Thanks a lot vigorous

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          You can right click on a file or folder that you want to grant ASP.NET write access, and hit Properties to open the Properties dialog box. On the Security tab, you click Add to add the ASPNET account to the list, and assign Write permission to it. There is one thing that you should be awared that you will not the Security tab in the Properties dialog if you are not joined to a domain. To display the Security tab, you should first open Folder Options ( go to Control Panel and see Folder Options or open Window Explorer, hit Tools menu and see Folder Options). On the View tad, under Advanced settings, clear "Use simple file sharing (Recommended)". In addition, you can also use impersonation to make your application able to write a file or change the account that the ASP.NET worker runs under to one with more permissions.

          W 1 Reply Last reply
          0
          • M minhpc_bk

            You can right click on a file or folder that you want to grant ASP.NET write access, and hit Properties to open the Properties dialog box. On the Security tab, you click Add to add the ASPNET account to the list, and assign Write permission to it. There is one thing that you should be awared that you will not the Security tab in the Properties dialog if you are not joined to a domain. To display the Security tab, you should first open Folder Options ( go to Control Panel and see Folder Options or open Window Explorer, hit Tools menu and see Folder Options). On the View tad, under Advanced settings, clear "Use simple file sharing (Recommended)". In addition, you can also use impersonation to make your application able to write a file or change the account that the ASP.NET worker runs under to one with more permissions.

            W Offline
            W Offline
            wk_vigorous
            wrote on last edited by
            #5

            Hi, I did it as you instructed but the file also can't be accessed with write mode. One question for ASP.NET account. what 's the meaning? Is it my user account? By the way I found the folder 's properties is always read-only even I chang it. The read-only properties comes back again. Do you think it is the reason? Anyway how can I write the file in ASP.NET? Thanks a lot. vigorous

            M 1 Reply Last reply
            0
            • W wk_vigorous

              Hi, I did it as you instructed but the file also can't be accessed with write mode. One question for ASP.NET account. what 's the meaning? Is it my user account? By the way I found the folder 's properties is always read-only even I chang it. The read-only properties comes back again. Do you think it is the reason? Anyway how can I write the file in ASP.NET? Thanks a lot. vigorous

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              The ASPNET account is normally used to run the ASP.NET worker process(aspnet_wp.exe), and it is automatically created during installation of the .Net framework. This account basically has limited permissions on the server mainly for the security reason. For more information on this account, you can look at this document: http://www.gotdotnet.com/team/upgrade/v1/aspnet_account_readme.doc[^] You can consult this document to see how to configure the process identity: http://support.microsoft.com/default.aspx?scid=kb;en-us;317012[^] The sample code demonstrates how write a file in ASP.NET, this method writes some text to the text.txt file located in the Data folder. To use this method, you just need to grant ASP.NET write access to the Data folder:

                private void WriteToTextFile(string text)
                {
                   string path = Server.MapPath("Data/text.txt");
                   FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write);
                   StreamWriter writer = new StreamWriter(stream);
                   writer.Write(text);
                   writer.Close();
                   stream.Close();
                }
              

              If you write to a file which is in read-only mode, the application will throw an error. I think you don't need to worry about what you found on the folder's properties.

              W 1 Reply Last reply
              0
              • M minhpc_bk

                The ASPNET account is normally used to run the ASP.NET worker process(aspnet_wp.exe), and it is automatically created during installation of the .Net framework. This account basically has limited permissions on the server mainly for the security reason. For more information on this account, you can look at this document: http://www.gotdotnet.com/team/upgrade/v1/aspnet_account_readme.doc[^] You can consult this document to see how to configure the process identity: http://support.microsoft.com/default.aspx?scid=kb;en-us;317012[^] The sample code demonstrates how write a file in ASP.NET, this method writes some text to the text.txt file located in the Data folder. To use this method, you just need to grant ASP.NET write access to the Data folder:

                  private void WriteToTextFile(string text)
                  {
                     string path = Server.MapPath("Data/text.txt");
                     FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write);
                     StreamWriter writer = new StreamWriter(stream);
                     writer.Write(text);
                     writer.Close();
                     stream.Close();
                  }
                

                If you write to a file which is in read-only mode, the application will throw an error. I think you don't need to worry about what you found on the folder's properties.

                W Offline
                W Offline
                wk_vigorous
                wrote on last edited by
                #7

                Really thank you very much for your great help. Now I can write the file. You are really a kind person and love to help others. Thanks again. vigorous

                M 1 Reply Last reply
                0
                • W wk_vigorous

                  Really thank you very much for your great help. Now I can write the file. You are really a kind person and love to help others. Thanks again. vigorous

                  M Offline
                  M Offline
                  minhpc_bk
                  wrote on last edited by
                  #8

                  Hi there, that's my pleasure.:-O Thank you for the kind words.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups