M
M
Matsun2017-04-08 02:04:54
ASP.NET
Matsun, 2017-04-08 02:04:54

ASP NET Identity - how to connect to a developed project?

I am developing my blog, I have already done some functionality, there are several tables in the database:
Articles
Categories
Pages.
For a DB the approach "First the Code" is used
Now I do futile attempts to fasten authorization.
I'm stuck at this moment.
I have 2 projects in VS - Domain and WebUI. In which is it more correct to implement ASP NET Identity?
And another question. I already have my own context for connecting to the database , which is inherited from DbContext, and here I also need to create an AppIdentityDbContext, which should be inherited from IdentityDbContext<Т>
public class EFDbContext : DbContext

public class AppIdentityDbContext : IdentityDbContext<AppUser>

Question - is it necessary to somehow create two contexts, or can it all be crammed into one? Of course I want to use one database. If possible, give an example.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2017-04-08
@evgshk

If you need an example, create an empty project in Visual Studio based on the ASP.NET MVC template, with the authorization item marked (Individual User Accounts it's called). Also the context of connection to a DB will be created to you. In addition, the simplest logic of registration, authorization, password recovery, etc. is automatically implemented. - there will be a lot to see.
UPD: In the "Pro" version of Freeman's book on MVC 5, Identity is given special attention. If I'm not mistaken, almost 100 pages - I recommend taking a look as well. Pro ASP.NET MVC 5 Platform

R
Roman, 2017-04-08
@yarosroman

Inherit your context from IdentityDbContext, not from DbContext and that's it, well, in the standard template, as Eugene said above, everything is there. And access is controlled by the [Authorize] attribute, you can mark both the action and the controller itself.

T
Timur, 2017-04-09
@OrenTiger

I have 2 projects in VS - Domain and WebUI. In which is it more correct to implement ASP NET Identity?

In fact, it would be more correct to make a separate project

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question