08.07.2019 - 12.07.2019 arası işler

- Unit Of Work uygulama örnekleri Link Link Link Link

- Mevcut projeye identity scaffold eklemek Link Link

Haftanın hatası: 

Migrate from asp.net 4.6 to .net core to avoid exception Invalid column name 'NormalizedUserName'
If you're using an existing database for Identity with 4.6 and when changing to use asp.net, some error might occur

Invalid column name 'NormalizedUserName'.

Invalid column name 'ConcurrencyStamp'.

Invalid column name 'LockoutEnd'.

Invalid column name 'NormalizedEmail'.

Invalid column name 'NormalizedUserName'.

=> Need to make change some tables, add more columns

The scripts in these links has some wrong :

http://copeanddrag.blogspot.com/2016/10/blog-post.html

https://stackoverflow.com/questions/38315812/use-a-identity-2-0-database-to-authenticate-a-asp-net-core-1-0-application

https://stackoverflow.com/questions/38315812/use-a-identity-2-0-database-to-authenticate-a-asp-net-core-1-0-application

[UserId]  should not be  NVARCHAR (450) NOT NULL, it has only 128 ( See in  AspNetUserRoles )

[LoginProvider]  should not be  NVARCHAR (450) NOT NULL, it has only 128 ( See in  AspNetUserLogins)

So that the [Name] of [AspNetUserTokens] should be 190 to make the PRIMARY KEY CLUSTERED ([UserId] ASC, [LoginProvider] ASC, [Name] ASC) not over 900 bytes.

Table AspNetUserTokens  and AspNetRoleClaims    do not existing in old Identity , so that do not need to drop them

So I make myself script:


Alter Table ASPNETROLES

ADD

 ConcurrencyStamp varchar(255) null,           

 NormalizedName varchar(255) null



 --Drop Table AspNetUserTokens



 CREATE TABLE [AspNetUserTokens] (

    [UserId]        NVARCHAR (128) NOT NULL,

    [LoginProvider] NVARCHAR (128) NOT NULL,

    [Name]          NVARCHAR (190) NOT NULL,

    [Value]         NVARCHAR (MAX) NULL,

    CONSTRAINT [PK_AspNetUserTokens]

 PRIMARY KEY CLUSTERED ([UserId] ASC, [LoginProvider] ASC, [Name] ASC)

)



Alter Table AspNetUsers

 Add

 ConcurrencyStamp varchar(255) null,

 LockoutEnd DateTime null,

 NormalizedEmail varchar(255) null,

 NormalizedUserName varchar(255) null



--Drop Table [AspNetRoleClaims]



CREATE TABLE [AspNetRoleClaims] (

    [Id]         INT            IDENTITY (1, 1) NOT NULL,

    [ClaimType]  NVARCHAR (MAX) NULL,

    [ClaimValue] NVARCHAR (MAX) NULL,

    [RoleId]     NVARCHAR (128) NOT NULL,

    CONSTRAINT [PK_AspNetRoleClaims]

 PRIMARY KEY CLUSTERED ([Id] ASC),

    CONSTRAINT [FK_AspNetRoleClaims_AspNetRoles_RoleId]

 FOREIGN KEY ([RoleId])

  REFERENCES [dbo].[AspNetRoles] ([Id]) ON DELETE CASCADE

)





GO

CREATE NONCLUSTERED INDEX [IX_AspNetRoleClaims_RoleId]

    ON [AspNetRoleClaims]([RoleId] ASC)



Alter Table AspNetUserLogins

   Add  ProviderDisplayName varchar(255) null


Bu değişikliklerden sonra mevcut kullanıcınız hata alıyorsa ilgili kullanıcının
 update dbo.AspNetUsers
  set [NormalizedEmail] = '',
      NormalizedUserName = ''
  Where Id = ''
bu alanlarını güncellemeniz gerekiyor. Bundan sonra mevcut kullanıcınız login olabilir.

Yorumlar

Bu blogdaki popüler yayınlar

Haproxy ve arkada 2 nginx server yönlendirme

04.06.2018 - 08-06.2018 arası işler