2

I have an asp.net web application running on IIS7 with it's AppPool Identity set as "NETWORK SERVICE" and Managed Pipeline Mode = Classic.

The web.config contains the following security settings...

<system.web>
    <identity impersonate="true"/>
    <authentication mode="Windows" />
</system.web>

The web app downloads data from a 3rd party and creates file(s) on the web app server. These files are then transferred to another server via this command.

  System.IO.File.Move(sourcePathAndFilename, destinationPathAndFileName);

When I run the app from the server as a high level user it works fine. When I run the app as any user from a client machine it fails. When I run the app as a low level authorized user from the server it fails.

The error is HTTP 401 unauthorized access.

I'm 100% sure users & NETWORK SERVICE have sufficient rights on both source and destination folders. So, it seems the File.Move() command is being executed as something else, but who/what?

Without changing the AppPool settings is there a way for the web app to pass through the user credentials to the File.Move() command?

cymorg
  • 534
  • 2
  • 10
  • 27

1 Answers1

3

You can find a great implementation of what you need in this question

after adding a specific class with a using statment you can do your File.Move

just with

using (new NetworkConnection(@"\\server\path", Credentials)) {
   System.IO.File.Move(sourcePathAndFilename, destinationPathAndFileName);
}
Community
  • 1
  • 1
faby
  • 7,394
  • 3
  • 27
  • 44
  • I wonder why this question isn't a duplicate of http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share – John Saunders Dec 19 '14 at 14:42
  • @JohnSaunders As you can see I have linked that question, `NetworkConnection` is a class implemented in that question. I have only done a match between the OP problem and another SO question that show the problem in a different way. – faby Dec 19 '14 at 14:45
  • I just sounds like this question should be closed as a duplicate of that question. I would have done so already except out of respect of your accepted answer. – John Saunders Dec 19 '14 at 14:47