问题标签 [asp.net-identity-3]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1706 浏览

asp.net-mvc - vNext. AspNet.Identity and custom UserStore. UserStore disposed exception

I'm trying to understand vNext.
I wrote custom UserStore, that works with MongoDB and implements these interfaces:

In Startup.cs added:

Then tried to use unchanged AccountController from Visual Studio template and have troubles.
When signing in i getting ObjectDisposedException in UserStore.FindByNameAsync() -- something called UserStore.Dispose().
In UserManager code on github.com/aspnet Store.Dispose() called only in UserManager.Dispose().
I can just ignore calls of Dispose and all works fine, but this is not good way.
So i have no ideas what shall i do

P.S. The Question is: what (and why) can call UserStore.Dispose()?

0 投票
0 回答
480 浏览

asp.net-identity - asp.net vnext 身份私人注册

我创建了 vNext 空项目。

添加了一些 API 和视图。

我还通过从 Register 方法中删除来禁用注册[AllowsAnonymous],因为我不想公开注册。

但我想要的是允许私人注册

我肯定需要一个“超级管理员”用户。

然后我看到了不同的方式:

  1. 邀请系统:site.com/register?invite-token,注册后或 X 小时后过期。超级管理员将能够创建此令牌。

  2. 每个人都可以注册,但只有批准(由超级管理员)的用户才能真正登录。

  3. 超级管理员手动创建用户。

最后是问题:

  • 如何安全地创建“超级管理员”用户?(我发布到天蓝色)

    我找到了一个例子,如何做到这一点:github,但是在代码中存储 opentext 传递看起来很糟糕。

  • 哪种方式最好或最多?是否有用于此类任务的知名软件包?
  • 任何这种方式都暗示着,只有管理员界面。如何正确保护它?
  • 如何扩展案例:“superadmin”>“admin”>“user”?
0 投票
2 回答
750 浏览

asp.net-core - 登录MVC6后用户角色为零?

我正在使用 Visual Studio 2015 中的默认站点模板。我添加了一些角色并为用户分配了角色。使用过的人登录时,角色为零。我需要做什么才能让角色发挥作用?

0 投票
2 回答
5728 浏览

asp.net-core - 如何在 Asp.net Identity 3.0 和 MVC 6 中打开角色?

我不确定我是否在这里遗漏了什么。即使用户具有某些角色,默认User.IsInRole()情况下也不起作用。

我没有自己的角色存储实现。我假设默认的应该可以工作。Startup.cs为了让角色发挥作用,我需要做些什么特别的事情吗?我正在使用 mvc 6 beta 2 默认模板。

0 投票
2 回答
2795 浏览

asp.net - How can the Identity.GetUserId() be made to return a Guid instead of a string?

I am using ASP.Net Identity 2 but soon hope to change to Identity 3 when it becomes more stable (anyone know when that might be?). Here's a sample of my code:

The Content table stores ModifedBy as a UNIQUEIDENTIFIER and the Content object assigns a datatype of Guid to ModifiedBy

When I look at the signature for GetUserId() it returns a string.

So how can I take the users UserId and put it into the ModifiedBy which is a Guid?

0 投票
3 回答
6462 浏览

asp.net - ASP .NET 5 MVC 6 身份 3 角色声明组

我目前正在寻找一种解决方案,以在 ASP .NET 5 MVC 6 和 Identity 3 中使用高级角色/组权限管理。我开始了一个新的 Preview Starter Web 项目,它带有一个集成的简单登录系统。

现在我需要一个具有以下功能的复杂“用户权限管理”:

  1. 用户可以在多个组/角色中
  2. 一个组/角色有许多访问对象(例如 CanAccessUser、CanEditUser...)
  3. 每个组/角色的这些访问对象(可能是声明?)相互补充
  4. (最终解决方案可选):另外=>访问对象(可能是声明)可以由组独立分配给用户

我已经看到身份已经广泛地为我提供了适合我的表结构。(例如 AspNetUsers、AspNetUserRoles、AspNetRoles、AspNetRoleClaims),

但是我缺少一个很好的示例/文档来使用它们。

对于 MVC 5,我使用了这个例子:用户有很多组,一个组可以有很多角色(角色是源代码中类/函数的访问对象) ASP.NET Identity 2.0:实现基于组的权限管理

这些要求的存在已经是一个工作示例,您不必重新发明轮子。

0 投票
2 回答
3395 浏览

asp.net-core - Microsoft.AspNet.Identity vnext 中的 UserValidator

我有一个问题,我在使用 microsoft.aspnet.identity 时无法使用电子邮件地址作为用户名(创建新项目时选择了个人用户帐户 - asp.net 5 的默认 mvc 项目模板)。我在很多地方都读到这是解决方案:

但是在新版本的asp.net身份中,UserManager似乎没有一个叫UserValidator的属性。“UserValidator”已被识别,但我想它现在以不同的方式添加到 UserManager 中。我在 UserManager 上看不到任何相关属性。

编辑:

“Identity”的 github 存储库中的单元测试对此案例进行了测试。它目前是此文件中的最后一个:

https://github.com/aspnet/Identity/blob/dev/test/Microsoft.AspNet.Identity.Test/UserValidatorTest.cs

我想这应该为答案提供一个线索,但我看不出这会在我的代码中出现在哪里。

0 投票
3 回答
3819 浏览

asp.net - 为什么这违反了类型约束?

我正在尝试自定义 ASP.NET Identity 3 以便它使用整数键:

这可以编译,但随后会引发运行时错误:

System.TypeLoadException

GenericArguments[0], 'TeacherPlanner.Models.ApplicationUser', on 'Microsoft.AspNet.Identity.EntityFramework.UserStore`4[TUser,TRole,TContext,TKey]' 违反了类型参数 'TUser' 的约束。

的签名UserStore是:

ApplicationUser正是一个IdentityUser<int>. 这不是它要找的吗?

0 投票
3 回答
18111 浏览

c# - 如何在 DI 中注册自定义 UserStore 和 UserManager

这是我的设置:

这是我的 UserStore 的定义

这是我的 UserManager 的定义

这是我的 DbContext 的定义:

这是我的 Startup.cs

此构造函数的依赖项将起作用:

这个不会:

任何人都知道我做错了什么?

0 投票
0 回答
1067 浏览

asp.net-core-mvc - 无法创建新的声明身份

我目前正在尝试从经过身份验证的用户公开一个字段,但是在尝试向经过身份验证的用户添加新声明时遇到了一些困难。

在 MVC5 中,我会做类似以下的事情:

但是,当我尝试在 MVC6 中执行此操作时,我遇到了缺少对象和方法的问题。CreateIdentityAsync() 和 DefaultAuthenticationTypes 似乎都丢失了,或者说是 Visual Studio,当我深入研究 Identity 源时,我可以看到 CreateIdentityAsync 不再存在,但是我似乎找不到任何关于 DefaultAuthenticationTypes 的信息。

现在在这一点上,我认为这是一个很好的选择,但在过去的几天里它一直让我发疯,并且很高兴了解什么是错误的或这是如何改变的。