Windows 認証を使用して、IIS 7 でホストされている Web サイトにアクセスしている現在認証されているユーザーを偽装しようとしましたが、別のサーバー上のファイルにアクセスしようとすると、ログイン要求がサーバーのイベント ログに表示されます。 ANONYMOUS LOGONとしてアクセスしようとしているファイルを含むサーバー:
An account was successfully logged on.
Subject:
Security ID: NULL SID
Account Name: -
Account Domain: -
Logon ID: 0x0
Logon Type: 3
New Logon:
Security ID: ANONYMOUS LOGON
Account Name: ANONYMOUS LOGON
Account Domain: NT AUTHORITY
Logon ID: 0x1e47ea9
...
開発環境から、またはIISサーバーのローカルホストでWebAppを直接実行すると、正しいユーザー資格情報が使用され、正常に動作します。
私のWeb.configには
<authentication mode="Windows" />
<identity impersonate="true" />
IIS 認証では、匿名認証を無効にし、Asp .NET 偽装を有効にし、Windows 認証を有効にしています。
私が試したコードでは(.NET Framework 4のc#)
string path = @"\\server1\project\test.csv";
((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();
StreamWriter sw = File.AppendText(path);
また
using (HostingEnvironment.Impersonate(WindowsIdentity.GetCurrent().Token))
{
//code
}
using (HostingEnvironment.Impersonate())
{
//code
}
そして、私が見つけた他のいくつかのさまざまな提案が投稿されました。
コードに直接の偽装行を含めずに System.Security.Principal.WindowsIdentity.GetCurrent().Name をチェックすると、偽装したい正しいドメイン/ユーザー資格情報が表示されます。到達しようとしています。
IIS サーバー上にないブラウザーを介して Web アプリにアクセスすると、Windows の資格情報が要求され、ボタンを押して上記のコードを実行すると、ログイン ボックスがポップアップし、Windows の情報を要求され、何があってもポップアップし続けます。私がそれを渡すもの。試行ごとに、server1 に新しいイベントが作成され、ANONYMOUS LOGON が接続されます。
私が読んだところによると、ダブル ホップの問題の認証の問題である可能性がありますが、これらの投稿のほとんどは単純なファイル共有ではなく SQL サーバーに関するものです。
エラーは次のとおりです。
Access to the path '\\server\project\test.csv' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path '\\server1\project\test.csv' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
任意のガイダンスをいただければ幸いです。