0

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

scripter78
  • 1,117
  • 3
  • 22
  • 50
  • well if you are constantly coming up with the same error I would suggest the following 1. Debug the code 2. add some more meaningful error handling and logging 3. check to see if you can manually create a .txt file on that share and if you can't then you have a Permissions issue going on there.. – MethodMan Sep 15 '14 at 20:04
  • the Network Service account is a built in account and only exists at the local machine. If you are in an Active Directory or other type of LDAP domain, then you need to run your site's application pool under a domain user and give that user rights to the file share. Plus you would have to configure the web folder to allow the user. – TechneWare Sep 15 '14 at 20:05
  • and for `Security Reasons` I would stay away from Impersonation personally – MethodMan Sep 15 '14 at 20:06
  • have you stepped thru the code..? also try looking at stream.readallbytes here is an example http://www.dotnetperls.com/file-readallbytes – MethodMan Sep 15 '14 at 20:09
  • On my dev box it works just fine with no issues, it's not till I place it on the live servers that I run into the issue. That being said since it's not throwing a live error I guess I can put some error handling in place to force the error to display while on the live server. Yeah I never messed with impersonation before because I always heard there is potential security issues, the only reason I was thinking about it in this case is because it is strictly an intranet site – scripter78 Sep 15 '14 at 20:26
  • So I discovered that for some reason my app pool was running under "Network Service" I changed it to ApplicationPoolIdentity and now I am getting same error but instead of pointing to Network Service it is now pointing to " Account name: IIS APPPOOL\sitename" – scripter78 Sep 15 '14 at 21:08
  • just for a testing purpose I changed out the Application Pool user to my AD account. I have access to all of the servers and network drives but I continue to get the same error. This happens by providing the UNC \\sharedrive\somefolder etc.. or mapping the network drive but when i map the network drive I get the error that Exception type: DirectoryNotFoundException – scripter78 Sep 16 '14 at 14:57

0 Answers0