当我尝试将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>(ApplicationRoleManager.Create);
完整的文章可在此处获取:http://www.codeproject.com/Articles/762428/ASP-NET-MVC-and-Identity-Understanding-the-Basics
原文地址:https://www.jb51.cc/aspnet/249100.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。