Custom Security for Blazor


I checked the Custom Security example for Angular and was able to use the code in CustomSecurity.cs to achieve most of the functionality I needed, but several aspects did not work. I was not able to implement in Blazor the equivalent of the 3 controllers found in your example in Server/Controllers/CustomSecurity.

Would you provide a working example of CustomSecurity implementation in a Server side Blazor app?


Those controllers shouldn't be required as they are the default generated ones. Everything is in the CustomSecurity.cs file - it event contains a custom Startup to register the custom implementations.

What expects do not work? Can you elaborate?

The page Application Users did not return any user though I was able to add new users and to login with the users I had added. I noticed that the public IQueryable Users property in my CustomSecurity.cs file never got invoked.

Minor detail, the app crashed when using admin because the ApplicationUser created has an Id that cannot be converted to an int. I corrected this by a change in th eLogin method of AccountController.cs by replacing

await signInManager.SignInWithClaimsAsync(new ApplicationUser { UserName = userName, Email = userName }, isPersistent: false, claims);


await signInManager.SignInWithClaimsAsync(new ApplicationUser { UserName = userName, Email = userName, Id = "0" }, isPersistent: false, claims);

Also, which fields from the AspNetUser table do I need to reproduce in my own custom User table? I have Username, Email, EmailConfirmed, Passwordhash. But what about the other fields such as AccessFailedCount, ConcurrencyStamp etc...


I will investigate and report back my findings.

The current demo uses the following fields: radzen-examples/mssql-db.sql at master · radzenhq/radzen-examples · GitHub

I recommend checking Microsoft's documentation as well.

I just published a new demo: radzen-examples/CustomSecurityBlazor at master · radzenhq/radzen-examples · GitHub

The SecurityService has been updated to use the new tables (Users and Roles) - this is needed to make the user management pages work.

There are few other changes in the CustomSecurity.cs file - the UserStore class implements one additional interface.

That works, thanks.

One issue though with your CustomSecurity application for Blazor: when I try to configure the access of a page, my custom roles do not appear and it says "No roles found. Run the application to add some roles" though I have 3 roles.

Is it possible for the custom roles to integrate in the IDE?

Radzen does not know how to retrieve custom roles in the IDE. You can however add custom roles by typing them in.