简体   繁体   中英

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. 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. It works well. However, we need MVC 6 version too.

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.

My RolesManagementController.cs works in 5, but in 6 I get a red line under " RoleManager(IdentityRole) "

在此处输入图片说明

Also, red lines under " .RoleExists( " and " .Update "). 在此处输入图片说明

Here are my using statements in 6 version:

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.

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. you should make your method async and return Task<T> or just Task and call role manager methods with the await keyword

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

Example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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