What Changed
In XAF Blazor UI v20.2, the Security System is initialized in the Startup.ConfigureServices method as a service (MySolution.Blazor.Server\Startup.cs). In v20.1, the Security System was initialized in the BlazorApplication constructor as a Module (MySolution.Blazor.Server\BlazorApplication.Designer.cs).
Reasons for Change
We changed the Security System initialization method according to Blazor architectural requirements.
Impact on Existing Apps
If a Blazor application with the Security System was created in v20.1, it will throw the following exception in v20.2 after a user logs in:
The initialization code for the Security System has been improved. This is a breaking change: please update your application as described in the following article: https://www.devexpress.com/bcid=T923425
To update your application, follow the steps below:
- Open the MySolution.Blazor.Server\BlazorApplication.Designer.cs file. Remove the code related to the Security System setup:
C#partial class Solution1BlazorApplication {
// ...
private void InitializeComponent() {
// ...
this.securityModule1 = new DevExpress.ExpressApp.Security.SecurityModule();
this.securityStrategyComplex1 = new DevExpress.ExpressApp.Security.SecurityStrategyComplex();
this.securityStrategyComplex1.SupportNavigationPermissionsForTypes = false;
// ...
this.authenticationMixed1 = new DevExpress.ExpressApp.Security.AuthenticationMixed();
// ...
this.securityStrategyComplex1.Authentication = this.authenticationMixed1;
this.securityStrategyComplex1.RoleType = typeof(DevExpress.Persistent.BaseImpl.PermissionPolicy.PermissionPolicyRole);
this.securityStrategyComplex1.UserType = typeof(DevExpress.Persistent.BaseImpl.PermissionPolicy.PermissionPolicyUser);
// ...
this.securityModule1.UserType = typeof(DevExpress.Persistent.BaseImpl.PermissionPolicy.PermissionPolicyUser);
// ...
this.Modules.Add(this.securityModule1);
this.Security = this.securityStrategyComplex1;
}
}
-
Open the MySolution.Blazor.Server\BlazorApplication.cs file. Remove the SetupAuthentication method call from the application constructor and delete this method.
-
Open the MySolution.Blazor.Server\Startup.cs file. Add the following code to the ConfigureServices method:
C#using DevExpress.ExpressApp.Security;
using DevExpress.Persistent.BaseImpl.PermissionPolicy;
// ...
public class Startup {
// ...
public void ConfigureServices(IServiceCollection services) {
// Initialize the Security System
services.AddXafSecurity(options => {
options.RoleType = typeof(PermissionPolicyRole);
options.UserType = typeof(PermissionPolicyUser);
options.Events.OnSecurityStrategyCreated = securityStrategy => ((SecurityStrategy)securityStrategy).RegisterXPOAdapterProviders(); // for XPO applications only
}).AddAuthenticationStandard().AddExternalAuthentication<HttpContextPrincipalProvider>();
}
}
- Change the AddCookie and LoginPath members, as shown below:
C#public void ConfigureServices(IServiceCollection services) {
// ...
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {
// options.LoginPath = "/XafLoginPage"; // v20.1 - this path needs to be changed.
options.LoginPath = "/LoginPage"; // v20.2+
});
}