简体   繁体   English

从MVC5到MVC6的对话无法使RoleManager工作

[英]MVC5 to MVC6 converstion can't get RoleManager to work

I am trying to upgrade an MVC 5 application to MVC 6. The only thing in the 5 application is the ability to administrate Users and Roles. 我正在尝试将MVC 5应用程序升级到MVC6。5应用程序中的唯一功能是管理用户和角色的能力。 It is a "template" we created at work to wrap around all MVC projects to give them all the "login, register, and roles" stuff you need for security. 这是我们在工作中创建的一个“模板”,用于包装所有MVC项目,以便为它们提供安全性所需的所有“登录,注册和角色”内容。 It works well. 它运作良好。 However, we need MVC 6 version too. 但是,我们也需要MVC 6版本。

We were able to get MVC 6 installed with single user authentication and now I am trying to port over the Roles process from the working MVC 5 application. 我们能够通过单用户身份验证安装MVC 6,现在我正尝试从工作的MVC 5应用程序移植到Roles流程。

My RolesManagementController.cs works in 5, but in 6 I get a red line under " RoleManager(IdentityRole) " 我的RolesManagementController.cs可在5中运行,但在6中,我在“ RoleManager(IdentityRole) ”下显示一条红线

在此处输入图片说明

Also, red lines under " .RoleExists( " and " .Update "). 此外,“ .RoleExists( “和” .Update “)下的红线 在此处输入图片说明

Here are my using statements in 6 version: 这是我的6版的using语句:

using System;
using System.Linq;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System.Collections.Generic;
using MVC6.Models;

and my using statements in 5 version are not that much different. 和我在5版中的using语句没有太大不同。

using System;
using System.Linq;
using System.Web.Mvc;
using Donut5.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

With the new version of Asp.net (Asp.net 5) those methods became async. 随着新版本的Asp.net(Asp.net 5),这些方法变得异步了。 you should make your method async and return Task<T> or just Task and call role manager methods with the await keyword 您应该使方法async并返回Task<T>或者仅返回Task并使用await关键字调用角色管理器方法

await _rolesManager.RoleExistsAsync(...)
await _rolesManager.UpdateAsync(...)

Example: 例:

public async Task MethodName()
{
    var role = await _rolesManager.RoleExistsAsync(...);
    await _rolesManager.UpdateAsync(...);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM