【发布时间】:2014-01-22 10:40:42
【问题描述】:
我在 .NET 4.5 的 ASP.NET Web 窗体中使用带有窗体身份验证的 Windows 身份基础 如何将 WIF 表单身份验证与我在 web.config 中定义的自定义成员资格提供程序和自定义角色提供程序相结合?
我想使用我的自定义会员提供程序从 SQL DB 加载其他用户信息,例如电子邮件、生日、头像 iamge。 我想使用我的自定义角色提供程序从 SQL DB 中为经过身份验证的用户获取所有角色。
我的认证方法Authenticate(userName, password)是从Login.aspx LoginButtonClick调用的:
public static ClaimsPrincipal Authenticate(string userName, string password)
{
var principal = AuthenticateWindowsUser(userName, password);
var inputIdentity = (WindowsIdentity)principal.Identity;
var outputIdentity = new ClaimsIdentity(inputIdentity.AuthenticationType);
outputIdentity.AddClaim(new Claim(ClaimTypes.Name, inputIdentity.Name));
return new ClaimsPrincipal(outputIdentity);
}
private static WindowsPrincipal AuthenticateWindowsUser(string userName, string password)
{
try
{
SecurityToken securityToken = new UserNameSecurityToken(userName, password);
var handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
//Uses default WindowsUserNameSecurityTokenHandler
return new WindowsPrincipal((WindowsIdentity)handlers.ValidateToken(securityToken)[0]);
}
catch (SecurityTokenValidationException ex)
{
ShowException(ex);
}
}
【问题讨论】:
标签: asp.net wif membership-provider roleprovider