当前位置: 首页>>代码示例>>C#>>正文


C# AuthenticationIdentityManager.LinkExternalIdentity方法代码示例

本文整理汇总了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;
                }
            }
        }
开发者ID:nnaidenov,项目名称:GoldstoneForum,代码行数:50,代码来源:RegisterExternalLogin.aspx.cs

示例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;
         }
     }
 }        
开发者ID:PetarPenev,项目名称:Telerik,代码行数:37,代码来源:RegisterExternalLogin.aspx.cs


注:本文中的AuthenticationIdentityManager.LinkExternalIdentity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。