SaaS CMS has officially launched! Learn more now.

How to customise Identity user model in CMS 12?

Vote:
 

We're looking to extend the user model (ApplicationUser) with an extra field. Following the CMS docs here (https://world.optimizely.com/documentation/developer-guides/CMS/security/episerver-aspnetidentity/), we have this setup:

public class CustomUser : ApplicationUser { public string CustomData { get; set; } }

// In Startup.cs:
services.AddCmsAspNetIdentity<CustomUser>();

With this, however, during application start, we encounter the error "SqlException, invalid column name 'CustomData' ". Upon investigation, this is because in the database, the table dbo.AspNetUsers does not have the column CustomData created.

Going through the internet researching this, it seems like there is consensus that the documentation failed to detail the migration step: updating the database to reflect this new change:

With this in mind, when we go into the database and manually add the column to the AspNetUsers table, the error goes away as expected. But Optimizely obviously does not recommend interfering with the database schema, and our implementation will eventually be hosted on DXP.

We have opened a support ticket (#893747), and Optimizely is currently processing it, but we wanted to try and see if others on the forums have solved this issue before, and what's the best practice recommendation to solving this issue.

#278989
Apr 22, 2022 6:48
Vote:
 

There's some migration information in the new document system https://docs.developers.optimizely.com/content-cloud/v12.0.0-content-cloud/docs/aspnetidentity that's replaced the world docs.

#278999
Apr 22, 2022 9:19
btranorchard - Apr 25, 2022 23:36
Hey there, thanks for the reply. I've tried the line in the docs page, but it looks like there isn't a configureSqlServerOptions argument in the AddCmsIdentity method. There is only configureIdentity and configureIdentityBuilder, and neither of them has the MigrationsAssembly option. I have the UI.AspNetIdentity package installed.
Vote:
 

A new version of episerver-identity is in testing that will automigrate the schema for you.  For now you can see the script here here

#279077
Apr 23, 2022 16:18
btranorchard - Apr 25, 2022 23:40
Hey there, thanks for the reply. During testing we certainly can run SQL scripts against the test instance, but eventually we will be hosting the site on DXP for production, and we're concerned about damaging the warranty agreement if we touch the database schema there. Will this script be safe for that use?
Scott Reed - Jul 18, 2022 11:10
Hey Mark, do you know if this new version has been released yet? Also btranorchard there's no warranty issues with the database schema, although it used to be against best practice to add stuff to the Optimizely databases that changed a while ago and it's standard now extend it
Daniel Isaacs - Jul 18, 2022 16:31
I think this was the release note: https://world.optimizely.com/documentation/Release-Notes/ReleaseNote/?releaseNoteId=CMS-21895

And, I _think_ this is the related docs: https://docs.developers.optimizely.com/content-cloud/v12.0.0-content-cloud/docs/aspnetidentity#migration
Vote:
 

We have decided instead to switch to using ApplicationUserManager and a claims-based approach to storing user information, since extending the user model at this time involves too much custom and risky database work.

#279228
Apr 26, 2022 7:15
Vote:
 

Hello,

Is there any update on this subject. I find nothing on the internet about extend applicationuser. I can not migrate new field to database.

Does anyone have solution for this issue. for now we need to use custom table to store extra fields.

Thanks.

#283786
Jul 16, 2022 8:28
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.