ASP.NETでWindows認証ログインについて
ASP.NETでWebサイト表示時、AD認証でユーザ情報を取得するようにする。
Web.config
<authentication mode="Windows" />
ADのドメインでのログインを盛業する場合は、以下の内容を追加
<configuration> <system.web> <authorization> <allow roles="domainname\Managers" /> <deny users="*" /> </authorization> </system.web> </configuration>
ASP.NETコード上では、User.Idenrityにより、情報にアクセスする。
System.Security.Principal.IIdentityより、以下の情報が取得可能
// ユーザーを識別するために使用する認証の種類。 // string AuthenticationType { get; } // ユーザーが認証されている場合は true。それ以外の場合は false。 // bool IsAuthenticated { get; } // コードが実行されている対象ユーザーの名前。 // string Name { get; } @User.Identity.AuthenticationType @User.Identity.IsAuthenticated @User.Identity.Name
Roleの確認など
User.IsInRole("role-name")