MVC5到MVC6的转换无法让RoleManager工作

时间:2016-01-09 01:57:19

标签: c# asp.net controller asp.net-core-mvc role-manager

我正在尝试将MVC 5应用程序升级到MVC 6.这个应用程序中唯一能够管理用户和角色的能力。它是我们在工作中创建的“模板”,用于包装所有MVC项目,为他们提供安全所需的所有“登录,注册和角色”。它运作良好。但是,我们也需要MVC 6版本。

我们能够通过单用户身份验证安装MVC 6,现在我正在尝试从工作的MVC 5应用程序移植Roles进​​程。

我的RolesManagementController.cs在5中工作,但在6中我在“ RoleManager(IdentityRole)”下得到一个红线

enter image description here

此外,“ .RoleExists(”和“ .Update ”)下的红线。 enter image description here

以下是我在6版本中使用的语句:

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;

和我在5版本中使用的语句差别不大。

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

1 个答案:

答案 0 :(得分:1)

使用新版本的Asp.net(Asp.net 5),这些方法变得异步。您应该制作方法async并返回Task<T>或仅Task,并使用await关键字调用角色管理员方法

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

示例:

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