我试图使用内置于用户角色管理中的Asp.net,但无法使其工作。我一直在尝试不同的方法。我要做的是运行一个测试控制器,初始化一些用户,并给他们分配一个用户角色。
string newRoleName = RoleName.Trim();
if (!Roles.RoleExists(newRoleName)) // here I get timeout error
// Create the role
Roles.CreateRole(newRoleName);我尝试的另一种方法是,
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>()); // here I get this error
// The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.
var appUser = new ApplicationUser
{
UserName = model.Email,
Email = model.Email
};
IdentityResult identityUserResult = UserManager.Create(appUser, model.Password);
roleManager.Create(new IdentityRole("Admin"));
UserManager.AddToRole(appUser.Id, "Admin");我不知道如何使它发挥作用。有人能给我指点好的教程吗?我使用azure作为我的存储空间,框架版本为4.5
发布于 2016-01-18 14:05:07
ASP.NET成员系统早在2005年就在ASP.NET 2.0中引入,自那时以来,web应用程序通常处理身份验证和授权的方式发生了许多变化。当您正在为网络、电话或平板电脑构建现代应用程序时,ASP.NET身份是对成员系统应该是什么的新看法。
2014年3月20日,ASP.NET团队发布了新身份框架的RTM2.0版本。新版本带来了一些期待已久的新特性,标志着所有类型的ASP.NET应用程序的安全和授权能力都有了实质性的扩展。 ASP.NET身份框架最初是在2013年作为ASP.NET成员系统的后续而引入的,这是多年来MVC应用程序的主要组成部分,但它已经开始显示出它的时代。最初,ASP.NET标识提供了一种有用的、虽然有些微不足道的API,用于管理使用ASP.NET构建的面向公共的web应用程序的安全性和授权。身份框架引入了现代特性,例如社交网络登录集成,以及易于扩展的用户模型定义。新的RTM发行版除其他外,还引入了以下特性:
Identity 2.0是对去年引入的原始版本的一次重大修订。随着众多新特性的出现,带来了一些额外的复杂性。如果像我一样,您最近刚刚找到了身份框架的第一次迭代,那么就做好准备吧。虽然您不会从零开始使用2.0版本,但是还有很多需要学习的地方。
https://stackoverflow.com/questions/34856463
复制相似问题