C
C#6mo ago
Gipper

How to assign roles to already created Users in ASP.NET Identity?

In ASP.NET I am trying to attribute Roles to specific users in my Database, I already have the users and the roles created in the AspNetUsers and AspNetRoles, but now I would like to attribute each to the other as I wish. Is it "safe" to do so manually, through the SQL Server Object Explorer? Will that work with the Authorize DataAnnotations later? If not what should I do?
16 Replies
Angius
Angius6mo ago
Should be something like UserManager.AddToRole(user, role)
Gipper
Gipper6mo ago
How do I get tge UserManager?
Angius
Angius6mo ago
From the DI for example, inject it
Gipper
Gipper6mo ago
But shouldn't I do it in Program.cs? Where then?
Angius
Angius6mo ago
Ah, you want to seed the roles?
Gipper
Gipper6mo ago
No, I've already seeded them
Angius
Angius6mo ago
Well, you want to seed the relationships
Gipper
Gipper6mo ago
yeah
Angius
Angius6mo ago
You can always just do that manually UserRoles is, IIRC, the join table of users to roles
Gipper
Gipper6mo ago
Will the authorization work then?
Angius
Angius6mo ago
Why wouldn't it? The roles and relationships of roles to users are stored in the database
Gipper
Gipper6mo ago
Don't know, it just feels like cheating to me lol I admit I'm being silly
Angius
Angius6mo ago
When the user logs in, the framework fetches user's roles from the DB and saves them as claims
Gipper
Gipper6mo ago
It should work, you're right, I dont see whu not
Angius
Angius6mo ago
Then, it can check those claims without hitting the db
Gipper
Gipper6mo ago
ok, I'll insert manually then, thanks
Want results from more Discord servers?
Add your server
More Posts
✅ how do I read a json file, edit it and save the edit in the json file?lets say we have a json file here: ```json { "meow" : 2 }``` 3 things Im wondering how to do(code bIs there a standard option to generate UUID version 7? (Guid)Hello, .NET provides a way to generate UUID v4 with `Guid.NewGuid()`, but this cannot be used as a What is the up-to-date version of AspNet.WebAPI?I am upgrading my console application to include Web Api, so i changed the sdk from `Microsoft.NET.S[WPF] How to edit multiple items in ListBox at onceI'm trying to edit multiple items using SelectionMode="Extended" to give the items a specific value,Please Help me. I spent 3 days trying to fix it to no avail.I am very new to coding and this is my first project. Trying to fix it but I couldnt manage it. httErrors while trying to build a VSA templatehttps://github.com/viceroypenguin/VsaTemplate/ I got errors while trying to build this templateSerialize value of property onlyGiven this code: https://dotnetfiddle.net/C3Pt3C How would I only serialize the value of the "TempTSometimes: Object Null Exception when using var rdr = await cmd.ExecuteReaderAsync();The cmd.ExecuteReaderAsync sometimes get NullException. Source: `public async Task<GetNavigationBaranyone knows how to createa shortcut to the target program?I'm also hoping this is doable without using third party librariesUnity missing assembly after nuget import?So I recently imported System.Management.Automation.dll from microsoft.powershell.sdk.6.1.2.nupkg (l