asp.net-mvc – 我的MVC 5模板中没有ApplicationRoleManager类
发布时间:2020-12-15 22:24:05 所属栏目:asp.Net 来源:网络整理
导读:当我尝试将app.CreatePerOwinContext(ApplicationRoleManager.Create)添加到configauth时,我被告知applicationRoleManager不存在.有人知道为什么吗? using Microsoft.Owin.Security.OAuth;using Microsoft.AspNet.Identity;using Microsoft.AspNet.Identity
当我尝试将app.CreatePerOwinContext(ApplicationRoleManager.Create)添加到configauth时,我被告知applicationRoleManager不存在.有人知道为什么吗?
using Microsoft.Owin.Security.OAuth; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Microsoft.Owin.Security.DataProtection; using Microsoft.Owin.Security.Google; using Owin; using System; using LaCeibaNetv4.Models; namespace LaCeibaNetv4 { public partial class Startup { // For more information on configuring authentication,please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Configure the db context and user manager to use a single instance per request app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 解决方法
我遇到了同样的问题并遇到了这个代码,我曾经将这个类添加到我的项目中:
public class ApplicationRoleManager : RoleManager<IdentityRole> { public ApplicationRoleManager(IRoleStore<IdentityRole,string> roleStore) : base(roleStore) { } public static ApplicationRoleManager Create( IdentityFactoryOptions<ApplicationRoleManager> options,IOwinContext context) { var manager = new ApplicationRoleManager( new RoleStore<IdentityRole>(context.Get<ApplicationDbContext>())); return manager; } } 另外,记得在启动时通过在Startup.Auth.cs中添加这段代码来配置它: app.CreatePerOwinContext<ApplicationRoleManager>(Application??RoleManager.Create); 完整的文章可在此处获取:http://www.codeproject.com/Articles/762428/ASP-NET-MVC-and-Identity-Understanding-the-Basics (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- asp.net – 使用ItemType进行强类型转发器控制?
- asp.net-mvc-3 – 显示模型中外键属性的显示值
- 使用.NET Class作为SSRS RDLC的数据源
- asp.net-mvc – 缺少Visual Studio 2012 MVC本地
- asp.net-mvc – 有没有人使用史蒂夫·桑德森的Mv
- asp.net – 如何摆脱丑陋的asp:菜单闪烁?
- asp.net – BC30561:’Html’不明确,从命名空间
- ASP.NET 谨用 async/await
- 从Asp.Net MVC 6 API返回JSON错误
- asp.net-core – 在Asp.Net Core中注入DbContext
热点阅读