Select theme:
Radzen Blazor Studio has replaced Radzen as the primary RAD tool for Blazor applications.
Radzen Blazor Studio offers a modern UI, enhanced features, and improved performance to streamline your development process.
The latest documentation for Radzen Blazor Studio is available here: https://www.radzen.com/blazor-studio/documentation/
Open Radzen Blazor Studio docsRadzen provides security support out of the box, more info can be found in our Security article. This guide demonstrates how to get current user.
1. Create new application with .NET server-side project, add new MSSQL data-source connected to Northwind database, auto-generate pages and enable security.
2. To get the name of the authenticated user you can do the following:
var userName = this.HttpContext.User.FindFirst(ClaimTypes.Name).Value;
Dim userName = Me.HttpContext.User.FindFirst(ClaimTypes.Name).Value
For .NET Core 2.x you need to decorate your class with [Authorize] attribute in order to access current authenticated user:
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
namespace [ApplicationName].Controllers.[DataSourceName]
{
[Authorize(AuthenticationSchemes="Bearer")]
public partial class OrdersController
{
}
}
Imports System.Security.Claims
Imports System.Threading.Tasks
Imports Microsoft.AspNetCore.Authorization
Imports Microsoft.AspNetCore.Identity
Namespace [ApplicationName].Controllers.[DataSourceName]
<Authorize(AuthenticationSchemes:="Bearer")>
Public Partial Class OrdersController
End Class
End Namespace
3. To authorize only certain roles to have access to controllers you can use again the Authorize
attribute:
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
namespace [ApplicationName].Controllers.[DataSourceName]
{
[Authorize(Roles="Administrator", AuthenticationSchemes="Bearer")]
public partial class OrdersController
{
}
}
Imports System.Security.Claims
Imports System.Threading.Tasks
Imports Microsoft.AspNetCore.Authorization
Imports Microsoft.AspNetCore.Identity
Namespace [ApplicationName].Controllers.[DataSourceName]
<Authorize(Roles:="Administrator", AuthenticationSchemes:="Bearer")>
Public Partial Class OrdersController
End Class
End Namespace
4. Run the application, login and check current user.
Radzen is free to use. You can also test the premium features for 15 days.
Start FreeSelect theme: