Reputation: 3523
Having read lots of articles and making lots of false starts I need some advise on adding Microsoft ASP.NET Identity to my existing ASP.NET Web Forms application. There are so many subtle differences between my existing application and typical samples out there that I don't know how to get off the ground. Here are some points about my existing application:
ID int PK
, no username (as such), Password, First Name, Surname, Email and some other properties. It also has a Roles table (4-5 entries) and a UserRoles table that provides many-many relationships. There is no "claims" as such other than properties on the User table.web.config
(basically, the database name and server instance name is populated dynamically)So, here are some the barriers, issues, questions I've come up with. Any advise on any of the questions below would be most appreciated:
async
code. Is this going to cause me problems with the ASP.NET Identity framework? I've heard that async
works best if implemented right through the call stack.HttpContext.User
for example?My Schema
CREATE TABLE [dbo].[User](
[ID] [int] IDENTITY(1,1) NOT NULL,
[OrganisationID] [int] NOT NULL,
[SaltHashPassword] [nvarchar](128) NOT NULL,
[FirstName] [nvarchar](64) NOT NULL,
[Surname] [nvarchar](64) NOT NULL,
[Email] [nvarchar](128) NULL,
--...
CONSTRAINT [PK_User] PRIMARY KEY NONCLUSTERED ([ID] ASC)
) ON [PRIMARY]
CREATE TABLE [dbo].[Roles](
[Role] [varchar](8) NOT NULL,
[Name] [varchar](32) NOT NULL,
[Description] [varchar](1000) NOT NULL,
[OrderNo] [tinyint] NOT NULL,
CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED ([Role] ASC)--...
CONSTRAINT [IX_Roles] UNIQUE NONCLUSTERED ([Role] ASC)--...
) ON [PRIMARY]
CREATE TABLE [dbo].[UserRole](
[UserID] [int] NOT NULL,
[Role] [varchar](8) NOT NULL,
CONSTRAINT [PK_UserRole] PRIMARY KEY CLUSTERED ([UserID] ASC,[Role] ASC)
) ON [PRIMARY]
Upvotes: 0
Views: 1920
Reputation: 688
That's a lot of questions here. I think a good starting point is this migration article: Migrating an Existing Website from SQL Membership to ASP.NET Identity
It will probably help you answer most of your questions here, especially 1, 3 and 4.
Answer to Question 2: As ASP.NET Membership and ASP.NET Identity are two different things, I would suggest a full migration, meaning that once you created the new tables for Identity, you map your foreign keys to the new tables and get rid of ASP.NET Membership tables.
Answer to Question 5: I think it depends how you want to set up ASP.NET Identity. In the project I am currently working on, we decided not to use Entity Framework at all, but this makes everything more complex as you have to get very deep knowledge of what happens, when, how, why... So if you are looking for easy implementation, use EF it makes life much more easy and you will find plenty of code samples on Internet.
Answer to Question 6: If you don't use async, it won't cause issues. The only downside is that you won't benefit from it...
Answer to Question 7: Microsoft does not recommend having multiple authentication systems activated. In the project I am currently working on, we managed to have both Identity and Azure AD authentication working together, but we had to develop our own middlewares and it was not that easy. In our web.config, we have:
<system.web>
...
<authentication mode="None" />
...
</system.web>
Upvotes: 2