mvc3サイトの特定のページ(管理者)にアクセスする権限を持っているかどうかを調べるには、現在のユーザーを知り、アクティブなディレクトリ設定(Windows Server 2008)私は建設中です。しかし、PrincipalContextを作成して現在のユーザに問い合わせると、サイトが実行しているアプリケーションプールが返されます。UserPrincipal.CurrentがIIS上でapppoolを返す
アイブ氏は試してみました:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal currentuser = UserPrincipal.Current;
string username = currentuser.DisplayName;
と
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain", "CN=dbcn LDAP,OU=the - account,DC=thedc,DC=local", "domain\\user", "password");
UserPrincipal currentuser = UserPrincipal.Current;
string username = currentuser.DisplayName;
をWeb.configファイルは、次のようになります。
<configuration>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
</appSettings>
<authentication mode="Windows" />
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
<providers>
<clear />
<add name="AspNetActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="service" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
<providers>
<clear />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<identity impersonate="false" />
<connectionStrings>
<add name="foocontext" connectionString="data source=foo;Initial Catalog=foo;Integrated Security=SSPI;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
<add name="ADService" connectionString="LDAP://foo.local/OU=the - service,DC=foo,DC=local" />
</connectionStrings>
</configuration>
アイブ氏は、2つの異なるアカウントでコンテキストをインスタンス化しようとした(なしアカウントで指定されました)、そのうちの1つは、IT管理者がクエリに使用するLDAPアカウントです。私はここで何が欠けていますか?なぜ、常に現在のユーザーとしてapppoolを返しますか?現在ログインしているユーザーを取得するにはどうしたらいいですか?
ありがとうございます! HttpContext.Userが何をしたいです
を検索した後、私のために働いていたものです。私は現在の(使用できません)を使用することはできませんし、キャストエラーが発生しましたが、 'string winPrincipalName = HttpContext.User.Identity.Name; '私に正しいユーザーを与えます。さて、ユーザーがどのADグループに属しているかを調べるにはどうすればいいですか? findbyidentityは常に私に結果を返します。 – user1168607