I am trying to write an uploaded FileStream from my web server to some other server, which is giving the error:
Logon failure: unknown user name or bad password.
Stack Trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
The application pool is running under “Network Service” and I have set the other server’s folder permissions for this user as “network service => full control”.
‘Network Service’ account on Machine A is not the same as ‘Network Service’ on Machine B. They are both machine-dependant identities, and you can’t target one on the other.
You can instead just give read/write on the target folder to ‘Everyone’ – that’ll work.
If you’re in a domain environment, then a common trick to get around issues like this is to use a domain account as the application pool identity – that way you can set the ACLs on the folder on Machine B because it can ‘see’ the identity being used by the app pool on Machine A.