イントラネット上にMVCWebアプリケーションがあり、FTPサーバー上にファイルを作成して外部のパートナーに送信できるようにしたいと考えています。
偽装のコードはWindowsImpersonationContextを使用します。
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
StreamWriter sw = System.IO.File.CreateText("PathOnFTPServer");
sw.Write("data");
impersonationContext.Undo();
何が起こっているのか、そして私の質問の理由は次のとおりです。
なりすまし前
User.Identity.Name:[私のWindowsクレデンシャル]
System.Security.Principal.WindowsIdentity.GetCurrent()。Name:NT AUTHORITY \ NETWORK SERVICE
なりすまし後
User.Identity:[私のWindowsクレデンシャル]
GetCurrent.Name:[私のWindowsクレデンシャル]
元になります
User.Identity:[私のWindowsクレデンシャル]
GetCurrent.Name:NT AUTHORITY \ NETWORK SERVICE
したがって、偽装する前は、現在のユーザーはシステムアカウントですが、偽装後は、FTPサーバー上にテキストファイルを作成する権限を持つWindowsドメインアカウントを使用しています。コードは、Visual Studio Webサーバーを使用してローカルで機能しますが、テストサーバーのIISに展開した場合は機能しません。
アクセス拒否エラーが発生します。正しいユーザーが偽装されている場合のエラーの理由は何ですか?