本文整理汇总了C#中AuthenticationIdentityManager.LinkExternalIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationIdentityManager.LinkExternalIdentity方法的具体用法?C# AuthenticationIdentityManager.LinkExternalIdentity怎么用?C# AuthenticationIdentityManager.LinkExternalIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthenticationIdentityManager
的用法示例。
在下文中一共展示了AuthenticationIdentityManager.LinkExternalIdentity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load()
{
// Process the result from an auth provider in the request
ProviderName = OpenAuthProviders.GetProviderNameFromRequest(Request);
if (String.IsNullOrEmpty(ProviderName))
{
Response.Redirect("~/Account/Login");
}
if (!IsPostBack)
{
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
var auth = Context.GetOwinContext().Authentication;
ClaimsIdentity id = manager.GetExternalIdentity(auth);
var context = new ApplicationDbContext();
var user = context.UserRoles.FirstOrDefault(u => u.User.UserName == id.Name);
if (user != null)
{
var userRole = user.Role.Name;
if (userRole == "Banned")
{
ErrorSuccessNotifier.AddErrorMessage("You are banned!");
ErrorSuccessNotifier.ShowAfterRedirect = true;
Response.Redirect("~/Account/Login");
}
}
IdentityResult result = manager.SignInExternalIdentity(auth, id);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else if (User.Identity.IsAuthenticated)
{
result = manager.LinkExternalIdentity(id, User.Identity.GetUserId());
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
AddErrors(result);
return;
}
}
else
{
userName.Text = id.Name;
}
}
}
示例2: Page_Load
protected void Page_Load()
{
// Process the result from an auth provider in the request
ProviderName = OpenAuthProviders.GetProviderNameFromRequest(Request);
if (String.IsNullOrEmpty(ProviderName))
{
Response.Redirect("~/Account/Login");
}
if (!IsPostBack)
{
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
var auth = Context.GetOwinContext().Authentication;
ClaimsIdentity id = manager.GetExternalIdentity(auth);
IdentityResult result = manager.SignInExternalIdentity(auth, id);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else if (User.Identity.IsAuthenticated)
{
result = manager.LinkExternalIdentity(id, User.Identity.GetUserId());
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
AddErrors(result);
return;
}
}
else
{
userName.Text = id.Name;
}
}
}