0

I have this code

enter image description here

As you can see Roles is highlighted and that is what is causing the problem. The error says

'Microsoft.AspNet.Identity.RoleManager' does not contain a definition for 'Roles' and no extension method 'Roles' accepting a first argument of type 'Microsoft.AspNet.Identity.RoleManager' could be found (are you missing a using directive or an assembly reference?)

It is saying are you missing reference or assembly? I am new to identity. I don't know what could be the problem. My header files seem to be fine

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using WebSite2;
TheTechGuy
  • 16,560
  • 16
  • 115
  • 136

1 Answers1

0

The problem seems to that of identity-1 vs identity-2. The code I was running was for identity v2 but I was working with identity v1 (Visual Studio 2013) and hence the error. Switching to identity v1 fixes the problem. The correct code for v1 is

var context = new ApplicationDbContext();

var allRoles = context.Roles.ToList();
ListView1.DataSource = allRoles;
ListView1.DataBind();

which fixes the problem. Relevent question Getting All Users and All Roles through asp.net Identity

Community
  • 1
  • 1
TheTechGuy
  • 16,560
  • 16
  • 115
  • 136