Why is access to the path denied?

前端 未结 29 1093
刺人心
刺人心 2020-11-22 15:25

I am having a problem where I am trying to delete my file but I get an exception.

if (result == \"Success\")
{
     if (FileUpload.HasFile)
     {
         t         


        
相关标签:
29条回答
  • 2020-11-22 15:58

    same issue for me too, I was pointing the folder instead of file.

    so make sure in path, give path+filename

    System.IO.File.WriteAllBytes("path", bytearray);
    
    0 讨论(0)
  • 2020-11-22 15:58

    I have also faced this issue when my window service started throwing the exception

    System.UnauthorizedAccessException: Access to the path "C:\\Order\\Media
    44aa4857-3bac-4a18-a307-820450361662.mp4" is denied.
    

    So as a solution, I checked the user account associated with my service, as shown in below screen capture

    So in my case it was NETWORK SERVICE

    And then went to the folder properties to check if the associated user account also exists under their permission tab. It was missing in my case and when I added it and it fixed my issue.

    For more information please check the below screen capture

    0 讨论(0)
  • 2020-11-22 16:00

    You need to modify the privileges of the folder you're trying to delete from/save to. Right-click on the containing folder and use the Security tab to permit modify rights for the user your application runs under.

    0 讨论(0)
  • 2020-11-22 16:00

    I had the same problem on a newly moved website on a shared server. Solved through the web host panel (DotNetPanel) setting true the "allow write permissions". So if you are in a shared server before reviewing all code worth taking a look at the server configuration and could save you a lot of time.

    0 讨论(0)
  • 2020-11-22 16:01

    When a user tries to connect to your Web site, IIS assigns the connection to the IUSER_ComputerName account, where ComputerName is the name of the server on which IIS is running. By default, the IUSER_ComputerName account is a member of the Guests group. This group has security restrictions. Try to grand access to IUSER_ComputerName to that folder

    Here is very good described answer about IIS security

    Hope this helps

    0 讨论(0)
  • 2020-11-22 16:01

    If this is an IIS website that is having the problem, check the Identity property of the advanced settings for the application pool that the site or application uses. You may find that it is set to ApplicationPoolIdentity, and in that case then this is the user that will have to have access to the path.

    Or you can go old style and simply set the Identity to Network Service, and give the Network Service user access to the path.

    0 讨论(0)
提交回复
热议问题