Results 1 to 11 of 11

Thread: UnauthorizedAccessException: Access denied.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235

    UnauthorizedAccessException: Access denied.

    I searched this forum but didn't find an answer, which really surprises me.

    In my ANP.NET code, I am trying to write to a file, but am getting an error:

    Access to the path "c:\inetpub\wwwroot\ASPNutshell\Blog6-7b\Blog.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\ASPNutshell\Blog6-7b\Blog.xml" is denied.

    The ASP.NET process is not authorized to access the requested resource. For security reasons the default ASP.NET process identity is '{machinename}\ASPNET', which has limited privileges. Consider granting access rights to the resource to the ASP.NET process identity.

    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 "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.
    Well, the message is wrong. There is no security tab in the properties window accessed through Explorer. My searchnig revealed that you have to change it in IIS, but apparently I don't know how to do that. I checked the write box on the Files tab in the properties window, but that doesn't seem to do it. I also granted write privileges to the application directory but that didn't work either.

    The problem is I don't really know IIS, so any pointers you can give me will be great. Also, are there any good resources on the inner workings of IIS?

    Thanks.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    OK, let's try this again. I have created a one-line program web app:

    Code:
    private void Page_Load(object sender, System.EventArgs e)
    {
    	// Put user code to initialize the page here
    	File.Create(@"C:\Inetpub\wwwroot\ASPNutshell\WriteFileExp\testFile.txt");
    }
    When I run the program, I get the following error:

    Access to the path "C:\Inetpub\wwwroot\ASPNutshell\WriteFileExp\testFile.txt" 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\ASPNutshell\WriteFileExp\testFile.txt" is denied.
    Surely someone around here has tried to create a file in ASP.NET. Even if someone says they tried this and it works, it would give me some direction...

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Sounds like your harddrive is setup as a Fat32 partitioning. You need NTFS setup to set permissions.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    No....The properties tab says File System is NTFS.

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this. In the user password console, give the aspnet account write privilege. If that does'nt work, open the web.config file and set impersonate to true.
    Dont gain the world and lose your soul

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    problem with impersonate is that if the ASPNET account doesnt have permission, then impersonating it wont do much good would it?

    that is strange that the Security tab doesnt show up, it should if you are on an NTFS setup.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    Originally posted by DevGrp
    Try this. In the user password console, give the aspnet account write privilege. If that does'nt work, open the web.config file and set impersonate to true.
    Please forgive my ignorance, but where is the user password console? I know I should know this, so don't berate me.

    Also, I am using Windows XP, which according to my friend, does not have a security tab on file properties. Mayby that's why I'm having such problems. I know I should kmow how to use my own OS better, but this is how I learn, right? Sure.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    hmmm.Havent used XP myself so I don t really know what the deal with that is. I have never heared of password console either.

    DevGrp?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    I figured out how to get the security tab. It's one of the settings in Folder Options -> view. Once I did this, I was able to follow the instructions above and create a file. Yay!

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Good. Security options just had to be somewhere.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Originally posted by Cander
    hmmm.Havent used XP myself so I don t really know what the deal with that is. I have never heared of password console either.

    DevGrp?
    I was referring to the local users and groups section under the computer managment console in the control panel.
    Dont gain the world and lose your soul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width