I've inherited a new project. The website (MVC.NET) is referencing a file location on the Windows 2012 server (it appears to be hard coded) but the file is not in the same directory as the website.
Part of the code copies a file from one location to another using File.Copy but this is causing an exception.
Apparently it was working yesterday and today it isn't. The website is down and as such I'm looking to resolve it.
The error message from the browser is
Access to the path 'C:\Websites\Website\Content\Images\Uploads\Certificate 1.jpg' 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:\Websites\Website\Content\Images\Uploads\Certificate 1.jpg' 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 and IIS 7, and the configured application pool identity on IIS 7.5) 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 access to a file, right-click the file in File 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.
The easiest way to fix this (as a temporary fix just to get the website up and running) I thought was to give full permissions to that folder, meaning adding Everyone
with full permission. It didn't work. I'm not curious as to why.
I'm aware of the risks this has but my question is why this doesn't work. Why do I still see the same error message?
I can RDP into the server and access the file without issue. As such, I don't believe this is a server issue (for ServerFault or SuperUser).
I suspect it's a protection thing in .NET. In the same way (if I remember right) we had to set special permissions in IIS to allow parent paths in ASP.
What do I need to do?
Edit
I've uploaded the website to another server and the same issue persists, suggesting the fault is not anything to do with the computer but more due to .NET or IIS
IIS is set to use Integrated Managed Pipe (not classic) and I've tried adding permission for NETWORK SERVICE and IUSR.