私はSilverlightクライアントとwcfサービスを持っています。アプリケーションには3つの認証モードがあります
- Active Directory
- Windowsパススルー
- 専有-私は明らかにこれに問題はありません。(Active Directoryとウィンドウパススルーの違いは本当にわかりません。ウィンドウパススルーを除いて、両方に同じコードを使用します。現在のユーザーを取得し、ADの場合、アプリはユーザー名パスワードの入力を求めます)
。
private string GetCurrentUser()
{
try
{
string result = WindowsIdentity.GetCurrent().Name;
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
result = wp.Identity.Name;
if (result.Contains(@"\"))
{
int position = result.LastIndexOf(@"\") + 1;
result = result.Substring(position);
}
return result;
}
catch (Exception ex)
{
return "";
}
}
WindowsIdentityとWindowsPrincipalはどちらも、「DefaultAppPool」または現在のスレッドが実行しているAppPoolを返します。Environment.UserNameでも同じものを返します。
web.configでオンにする<identity impersonate ="true"/>
と、Silverlightクライアントがwcfに接続できません。「見つかりません」エラーが発生します。だから、私は保つ必要があります<identity impersonate ="false"/>
必要なのは、現在ログオンしているユーザーだけです。これが難しいことを知りませんでした。