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
  1. Home
  2. General Programming
  3. C#
  4. Access denied

Access denied

Scheduled Pinned Locked Moved C#
csharpvisual-studiosysadminwindows-adminhelp
8 Posts 5 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.
  • J Offline
    J Offline
    jon 80
    wrote on last edited by
    #1

    I'm running a little code that should write code to a text file within the application directory, however I'm getting the following error: Access to the path c:\inetpub\wwwroot\MapFile\Mapped.txt is denied I'm logged on as Administrator on Windows Server 2008 and running VS 2008 SP1 / .NET 3.5. Any ideas?

    Jon

    I T D M 4 Replies Last reply
    0
    • J jon 80

      I'm running a little code that should write code to a text file within the application directory, however I'm getting the following error: Access to the path c:\inetpub\wwwroot\MapFile\Mapped.txt is denied I'm logged on as Administrator on Windows Server 2008 and running VS 2008 SP1 / .NET 3.5. Any ideas?

      Jon

      I Offline
      I Offline
      I am BATMAN
      wrote on last edited by
      #2

      Navigate to that folder, view the properties -> security. Give Users write permissions.

      1 Reply Last reply
      0
      • J jon 80

        I'm running a little code that should write code to a text file within the application directory, however I'm getting the following error: Access to the path c:\inetpub\wwwroot\MapFile\Mapped.txt is denied I'm logged on as Administrator on Windows Server 2008 and running VS 2008 SP1 / .NET 3.5. Any ideas?

        Jon

        T Offline
        T Offline
        Tony Richards
        wrote on last edited by
        #3

        This can also come up if the file has already been opened somewhere else in your code and you've forgotten to close it.

        My Blog: This Blog

        1 Reply Last reply
        0
        • J jon 80

          I'm running a little code that should write code to a text file within the application directory, however I'm getting the following error: Access to the path c:\inetpub\wwwroot\MapFile\Mapped.txt is denied I'm logged on as Administrator on Windows Server 2008 and running VS 2008 SP1 / .NET 3.5. Any ideas?

          Jon

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          If this is an ASP.NET application, the accout you're using to run this code under the debugger doesn't matter. It's actually running under the ASPNET account, which IIRC, by default, does not have Write permissions to the application folder. In order to make this work, and I do NOT recommend this, you have to give the ASPNET account Write permissions to the C:\inetpub\www\MapFile folder.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          J 1 Reply Last reply
          0
          • D Dave Kreskowiak

            If this is an ASP.NET application, the accout you're using to run this code under the debugger doesn't matter. It's actually running under the ASPNET account, which IIRC, by default, does not have Write permissions to the application folder. In order to make this work, and I do NOT recommend this, you have to give the ASPNET account Write permissions to the C:\inetpub\www\MapFile folder.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            J Offline
            J Offline
            jon 80
            wrote on last edited by
            #5

            Yeah I thought so, but what is the ASP.net acct used? When checking the users on the OS there were none other than the Administrator and another one created by sql server. This is not a production environment, so I'm not worried about security, but it's good to know.

            Jon

            D 1 Reply Last reply
            0
            • J jon 80

              I'm running a little code that should write code to a text file within the application directory, however I'm getting the following error: Access to the path c:\inetpub\wwwroot\MapFile\Mapped.txt is denied I'm logged on as Administrator on Windows Server 2008 and running VS 2008 SP1 / .NET 3.5. Any ideas?

              Jon

              M Offline
              M Offline
              Member 4187998
              wrote on last edited by
              #6

              This method should work for you. public static void AddFileSecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) { try { // Create a new FileInfo object. FileInfo fInfo = new FileInfo(FileName); // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = fInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. fSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType)); // Set the new access settings. fInfo.SetAccessControl(fSecurity); } catch (Exception exp) { Console.WriteLine(exp.Message.ToString()); Console.Read(); } } You can use it with something like this: FileWritePermission.AddFileSecurity(path, "everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow); Cheers

              D 1 Reply Last reply
              0
              • J jon 80

                Yeah I thought so, but what is the ASP.net acct used? When checking the users on the OS there were none other than the Administrator and another one created by sql server. This is not a production environment, so I'm not worried about security, but it's good to know.

                Jon

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                jon_80 wrote:

                but what is the ASP.net acct used?

                Depends on the server being used. If it's the development web server that comes with Visual Studio, it's "ASPNET". If it's IIS 6.0 and below, it'll probably be something like "IUSR_machineName". For IIS 7.0 and above, I think this name got changed to just "IUSR".

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                1 Reply Last reply
                0
                • M Member 4187998

                  This method should work for you. public static void AddFileSecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) { try { // Create a new FileInfo object. FileInfo fInfo = new FileInfo(FileName); // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = fInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. fSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType)); // Set the new access settings. fInfo.SetAccessControl(fSecurity); } catch (Exception exp) { Console.WriteLine(exp.Message.ToString()); Console.Read(); } } You can use it with something like this: FileWritePermission.AddFileSecurity(path, "everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow); Cheers

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Cute code, but an account (and core running under that account) cannot grant more permissions to itself, nor anyone else, than it already has.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

                  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