I am trying to create a file on a network share drive and continually coming up with the same error
Event Log Error
Event code: 4011
Event message: An unhandled access exception has occurred.
Event time: 9/15/2014 3:42:45 PM
Event time (UTC): 9/15/2014 7:42:45 PM
Event ID: c502025e2cb2a987asfas98as987732
Event sequence: 14
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT-1-130552837386928589
Trust level: Full
Application Virtual Path: /
Application Path: D:\Sites\website\
Machine name: ComputerName01
Process information:
Process ID: 1732
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Request information:
Request URL: http://website.com/requestedURL
Request path: /requestedURL
User host address: 25.33.33.23
User: CORP\SomeUser
Is authenticated: True
Authentication Type: Negotiate
Thread account name: NT AUTHORITY\NETWORK SERVICE
Custom event details:
The Event Log I changed the protected information like the IP address and URL etc. to false values to protect my data.
Below is the code I have been using and I have looked up on google and here and I have found similar issues but not the same issues in the long run. I assume I have to impersonate the NT AUTHORITY\NETWORK SERVICE but I am lost as to how to do so. Also I don't think this is too big of a deal but I am on a web farm with dual servers
Oh and I have tried just mapping the drive with a mapping of k:\ but that still comes up with the same exact error
using (FileStream file = new FileStream(@"\\SharedDrive\PDF\SomeFileName.pdf", FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
file.Write(bytes, 0, bytes.Length);
stream.Close();
}
EDIT: I have changed the Application to run off of my own Active Directory Login with the same result. I do have access to the directory and to create and modify files in that directory The error remains