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


C# ClaimsIdentity.GetUserId方法代码示例

本文整理汇总了C#中System.Security.Claims.ClaimsIdentity.GetUserId方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsIdentity.GetUserId方法的具体用法?C# ClaimsIdentity.GetUserId怎么用?C# ClaimsIdentity.GetUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Claims.ClaimsIdentity的用法示例。


在下文中一共展示了ClaimsIdentity.GetUserId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveItem

 public void SaveItem(ClaimsIdentity identity, Int32 listId, Int32 id, String text)
 {
     var userId = identity.GetUserId();
     var item = new PlanListItem() { Id = id, Text = text };
     this._repository.SaveItem(userId, listId, item);
     this._repository.SaveChanges();
 }
开发者ID:MechTrigger,项目名称:CCLabs,代码行数:7,代码来源:PlanListService.cs

示例2: SaveList

 public void SaveList(ClaimsIdentity identity, Int32 id, String name)
 {
     var userId = identity.GetUserId();
     var list = new PlanList() { Id = id, Name = name };
     this._repository.SaveList(userId, list);
     this._repository.SaveChanges();
 }
开发者ID:MechTrigger,项目名称:CCLabs,代码行数:7,代码来源:PlanListService.cs

示例3: CustomIdTest

 public void CustomIdTest()
 {
     var id = new ClaimsIdentity(
         new[]
         {
             new Claim(ClaimTypes.NameIdentifier, "3", null, ExternalAuthenticationType),
         },
         ExternalAuthenticationType);
     Assert.Equal(3, id.GetUserId<int>());
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:10,代码来源:IdentityExtensionsTest.cs

示例4: ExternalLoginCallback

        public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
            if (loginInfo == null)
            {
                return RedirectToAction("Index", "login");
            }
            //若使用者已經有登入資料,請使用此外部登入提供者登入使用者
            if (loginInfo != null)
            {
                var id = new ClaimsIdentity(loginInfo.ExternalIdentity.Claims,
                                            DefaultAuthenticationTypes.ApplicationCookie);

                Session["Account"] = id.GetUserId();
                Session["uname"] = loginInfo.DefaultUserName; //取得用戶名稱
                Session["resAccount"] = loginInfo.Login.LoginProvider;//取得用戶來源

                //var resourceAccount = loginInfo.Login.LoginProvider; 
                //TODO: 驗證邏輯,註冊會員邏輯    
                Member m = new Member();
                MemberData md = new MemberData();
                if (Session["Account"] != null)
                {
                    var memberData = md.Get().ToList().Where(a => a.uAccount == Session["Account"].ToString()).SingleOrDefault();
                    if (memberData == null)
                    {
                        m.uAccount = Session["Account"].ToString();
                        m.uName = loginInfo.DefaultUserName;
                        m.wdate = DateTime.Now;
                        m.udate = DateTime.Now;
                        m.uPassWord = "no";
                        m.uphone = "";
                        m.memberID = DateTime.Now.ToString("yyyyMMdd") + (md.Get().Count + 1).ToString().PadLeft(3, '0');
                        m.isdel = 0;
                        m.sort = 5000;
                        switch (loginInfo.Login.LoginProvider)
                        {
                            case "Facebook":
                                m.FacebookId = id.GetUserId();
                                m.GoogleId = "";
                                m.uemail = loginInfo.Email ?? "";
                                break;
                            case "Google":
                                m.FacebookId = "";
                                m.GoogleId = id.GetUserId();
                                m.uemail = loginInfo.Email;
                                break;
                            default:
                                m.FacebookId = "";
                                m.GoogleId = "";
                                m.uemail = "";
                                break;
                        }


                        md.Create(m);
                        TempData["Congu"] = "已成為會員";
                    }

                }

                //End: 加上你的驗證邏輯,或是註冊會員邏輯
                AuthenticationManager.SignIn(id);

                return RedirectToLocal(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "login");
            }


            // 若使用者已經有登入資料,請使用此外部登入提供者登入使用者
            //var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
            //switch (result)
            //{
            //    case SignInStatus.Success:
            //        return RedirectToLocal(returnUrl);
            //    case SignInStatus.LockedOut:
            //        return View("Lockout");
            //    case SignInStatus.RequiresVerification:
            //        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
            //    case SignInStatus.Failure:
            //    default:
            //        // 若使用者沒有帳戶,請提示使用者建立帳戶
            //        ViewBag.ReturnUrl = returnUrl;
            //        ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
            //        return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
            //}
        }
开发者ID:boy22200011,项目名称:funnmtbProject,代码行数:90,代码来源:AccountController.cs

示例5: GetListById

 public PlanListViewModel GetListById(ClaimsIdentity identity, Int32 id)
 {
     var userId = identity.GetUserId();
     var list = this._repository.Get(userId, id);
     return Mapper.Map<PlanListViewModel>(list);
 }
开发者ID:MechTrigger,项目名称:CCLabs,代码行数:6,代码来源:PlanListService.cs

示例6: GetAllLists

 public IList<PlanListViewModel> GetAllLists(ClaimsIdentity identity)
 {
     var userId = identity.GetUserId();
     var lists = this._repository.GetAll(userId);
     return Mapper.Map<IList<PlanListViewModel>>(lists);
 }
开发者ID:MechTrigger,项目名称:CCLabs,代码行数:6,代码来源:PlanListService.cs

示例7: DeleteList

 public void DeleteList(ClaimsIdentity identity, Int32 id)
 {
     var userId = identity.GetUserId();
     this._repository.DeleteList(userId, id);
     this._repository.SaveChanges();
 }
开发者ID:MechTrigger,项目名称:CCLabs,代码行数:6,代码来源:PlanListService.cs

示例8: RemoveExternalClaims

        private async Task<ClaimsIdentity> RemoveExternalClaims(ClaimsIdentity userIdentity, string loginProvider) {
            var currentClaims = await UserManager.GetClaimsAsync(userIdentity.GetUserId());
            foreach (var providerClaim in AuthenticationManager.User.Claims.Where(c => c.Type.StartsWith("urn:" + loginProvider.ToLower()))) {
                if (!providerClaim.Type.StartsWith("http://schemas.xmlsoap.org/ws/2005/05/identity/claims")) {
                    if (userIdentity.HasClaim(c => c.Type == providerClaim.Type)) {

                        if (userIdentity.HasClaim(c => c.Type == providerClaim.Type)) {
                            var toRemoveClaim = userIdentity.Claims.FirstOrDefault(c => c.Type == providerClaim.Type);
                            if (toRemoveClaim != null) {
                                userIdentity.RemoveClaim(toRemoveClaim);
                            }
                        }

                        // remove from database
                        var currentClaim = currentClaims.FirstOrDefault(c => c.Type == providerClaim.Type);
                        if (currentClaim != null)
                            await UserManager.RemoveClaimAsync(userIdentity.GetUserId(), currentClaim);
                    }
                }
            }
            return userIdentity;
        }
开发者ID:nonintanon,项目名称:zupzip9,代码行数:22,代码来源:AccountController.cs

示例9: StoreExternalClaims

        private async Task<ClaimsIdentity> StoreExternalClaims(ClaimsIdentity userIdentity) {
            ClaimsIdentity externalIdentity = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
            if (externalIdentity != null) {
                var currentClaims = await UserManager.GetClaimsAsync(userIdentity.GetUserId());
                foreach (var claim in externalIdentity.Claims) {
                    if (!claim.Type.StartsWith("http://schemas.xmlsoap.org/ws/2005/05/identity/claims")) {

                        if (userIdentity.HasClaim(c => c.Type == claim.Type && c.Issuer.Contains("LOCAL"))) {
                            var toRemoveClaim = userIdentity.Claims.FirstOrDefault(c => c.Type == claim.Type && c.Issuer.Contains("LOCAL"));
                            if (toRemoveClaim != null) {
                                userIdentity.RemoveClaim(toRemoveClaim);
                            }
                        }

                        if (!userIdentity.HasClaim(claim.Type, claim.Value)) {
                            // Add to claims
                            userIdentity.AddClaim(claim);

                            // Remove current claim
                            var currentClaim = currentClaims.FirstOrDefault(c => c.Type == claim.Type);
                            if (currentClaim != null)
                                await UserManager.RemoveClaimAsync(userIdentity.GetUserId(), currentClaim);

                            // Store claim to database
                            await UserManager.AddClaimAsync(userIdentity.GetUserId(), claim);
                        }
                    }
                }
            }

            return userIdentity;
        }
开发者ID:nonintanon,项目名称:zupzip9,代码行数:32,代码来源:AccountController.cs

示例10: NoIdReturnsDefaultValue

 public void NoIdReturnsDefaultValue()
 {
     var id = new ClaimsIdentity();
     Assert.Equal(0, id.GetUserId<int>());
 }
开发者ID:tomi85,项目名称:aspnetidentity,代码行数:5,代码来源:IdentityExtensionsTest.cs


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