asp.net-mvc – 我的MVC 5模板中没有ApplicationRoleManager类
发布时间:2020-05-24 08:53:34 所属栏目:asp.Net 来源:互联网
导读:当我尝试将app.CreatePerOwinContext(ApplicationRoleManager.Create)添加到configauth时,我被告知applicationRoleManager不存在.有人知道为什么吗? using Microsoft.Owin.Security.OAuth;using Microsoft.AspNet.Identity;using Microsoft
|
当我尝试将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 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如何使用ASP.NET MVC实现自定义缓存提供程序
- 使用IIS/ASP.NET反向AJAX
- ASP.NET上的ASP.NET未来?
- asp.net – 如何实时压缩和流量到Response.Output实时?
- asp.net-mvc-3 – MVC 3(Razor) – 使用Button事件调用Cont
- 在使用ASP.NET会话时是否可以强制请求并发?
- asp.net – jQuery弹出窗口返回父级的值
- asp.net – 使用Cookie进行Web会话状态 – 有哪些缺陷?
- asp.net-mvc – 为什么必须将LESS文件设置为Build Action“
- 如何在服务器控件属性中使用ASP.NET %=标签?
推荐文章
站长推荐
- asp.net – 不引用MVC的AllowHtml属性
- asp.net – 当HttpContext属性返回null时如何检索
- asp.net核心 – 无法在IISExpress中启动ASP.NET
- 在ASP.NET 5中获取AuthenticationProperties
- asp.net-web-api – 如何为代理控制器设置Web AP
- asp.net – System.Reflection.Assembly.LoadFil
- asp.net-mvc – Kendo UI Grid一次只扩展一行
- asp.net-mvc – 如何在ASP.NET MVC视图中使用扩展
- 与ASP.net WEB API进行交易
- asp.net-mvc – 如何asp.net(mvc)服务器返回错误
热点阅读
