I have an ASP.NET application that uses the Roles.GetRolesForUser method. The penalty call works in the application, but when I use the same call in the reference library, it throws an exception. Exception Message:
Roles.GetRolesForUser
Object reference not set to object instance
The strange thing is that when I check the roles, it is created.
My code is as follows:
var roles = Roles.GetRolesForUser(userName);
Any suggestions?
NOTE: according to the OP comment itself, this answer solved its problem.
This is a .NET error .To solve this problem, call:
string[] roles = Roles.Provider.GetRolesForUser(userName);
here is a very similar question.
In MVC 5, you can get user roles using the GetRoles(Id) method.But before using GetRoles you need to make a userManager object:
GetRoles(Id)
GetRoles
userManager
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)); var d = userManager.GetRoles(5);
Source: https://habr.com/ru/post/957481/More articles:Get audio samples from an audio element - javascriptSSL version error when cloning in https TortoiseHG - windows-7multiple connections in 1 project with sftp (sublime text 2) - sublimetext2How SVN merges two branches, where the same folder is added to both branches - mergeRunning a trigger sequentially after several parallel builds in TeamCity - performanceAndroid Google Plus SDK: how to get callback on +1 button (PlusOneButton) - androidDynamically adding triggers on UpdatePanel for dynamically added controls - c #What is the fastest way to find tags pointing to Commits? - libgit2How to initialize a circular dependency (final fields refer to each other)? - javaHow to connect to a low energy bluetooth device - c ++All Articles