バックグラウンド:
外部 API に接続する MVC 5/C# アプリがあります。Active Directory
ユーザーのPrincipal Context
認証を使用します。アプリUserPrincipal.Current
は、Un/Pw コンボが Db に格納されているかどうかを確認し、後で外部 API での操作に使用できるようにします。
public bool IsUserSetup()
{
try
{
// find currently logged in user
var user = UserPrincipal.Current; // <- ERRS HERE -----
// check if this user exists in Db with creds
if (user != null)
{
var u = _userProfileRepository.GetUserProfileByUserSID(user.Sid.ToString());
if (u != null
&& !string.IsNullOrEmpty(u.RallyUsername)
&& !string.IsNullOrEmpty(u.RallyPassword)
&& u.IsActive // <-- make sure this person is an active user
)
{
return true;
}
}
}
catch (Exception ex)
{
string exMessage = ex.Message;
//throw ex;
}
return false;
}
UserPrincipal.Current
デフォルトでアプリケーション プールの ID が返されることを理解しています。- また、Impersonate を True IIS に設定すると、次のように現在のユーザーのコンテキストが使用されることも理解しています。
<system.web> <identity impersonate="true"/>...
ただし、偽装をオン (true) にすると、次のようになります。
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
したがって、app pool
「クラシック」を使用するように変更します(これは、私が取るべき答えまたはパスではないと思います)。次のエラーが表示されます。
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.
明らかに、これは IIS Express でうまく機能します。私 (ドメイン\ユーザー名) は問題なく認識されます。しかし、IIS に切り替えるか、実際の Web サーバーにデプロイすると、これらの問題が発生します。
現在のユーザー/プリンシパルを取得して、ID と資格情報を外部 API にデータベースに保存できるようにする必要があります。次に、サイト/アプリを使用すると、自動的に資格情報を使用して、必要に応じて API で作業を行います。
次のいずれかを行うにはどうすればよいですか。
- 偽装が機能するように IIS をセットアップする
- 同じことをするようにコードを調整します