Tag: 身份

如何根据用户角色操作WPF GUI

我使用.NET的IIdentity和IPrincipal对象来实现基于角色的安全性,我正在修改基于当前用户所拥有的角色显示的控件。 我的问题是推荐的方法是在WPF窗口中启用/禁用字段 – 显示/隐藏依赖于IIdentity.IsInRole类型调用的字段。 这可以在XAML中完成,还是我必须将其抽象为代码,我认为后面的代码有点混乱; this.txtUserName.IsReadOnly = !MyPrincipal.CurrentPrincipal.IsInRole(“Administrator”); this.mnuCreateUser.Visibility = MyPrincipal.CurrentPrincipal.IsInRole(“Administrator”); ? Visibility.Hidden : Visibility.Visible; (注意;我的代码在执行函数时检查角色,我要做的是根据角色修改GUI,因此用户看不到/看到他们无权访问的只读元素)

成功登录后,User.Identity.GetUserId()返回null

我已经定义了一个临时变量来获取当前用户ID,它总是返回null。 这是快照: 为什么? 更新: // // POST: /Account/Login [HttpPost] [AllowAnonymous] public async Task Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return Json(new { success = false, ex = “Fail to login.” }); } var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, isPersistent: true, shouldLockout: false); switch (result) { case SignInStatus.Success: string userId = User.Identity.GetUserId(); return Json(new […]

用户很快就会退出

我正在使用ASP.NET身份会员资格。 这是Startup.Auth.cs代码: app.CreatePerOwinContext(EFDbContext.Create); app.CreatePerOwinContext(ApplicationUserManager.Create); app.CreatePerOwinContext(ApplicationSignInManager.Create); // Enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider // Configure the sign in cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath […]

ASP.NET Identity 2.0检查当前用户是否处于角色IsInRole中

使用ASP.NET Identity 2.0,您如何检查当前登录的用户是否在角色中? 我正在使用以下内容,但想知道是否有更高效的东西。 var um = new UserManager(new UserStore(new DbContext())); var au = um.FindByEmail(Context.User.Identity.GetUserName()); var inrole = um.IsInRole(au.Id, “Admin”); if (inrole) { }