Breaking Change T923425
Visible to All Users

Blazor - The Security System is initialized as a service in ConfigureServices instead of BlazorApplication

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:

  1. 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; } }
  1. Open the MySolution.Blazor.Server\BlazorApplication.cs file. Remove the SetupAuthentication method call from the application constructor and delete this method.

  2. 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>(); } }
  1. 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+ }); }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.