Adding User Authentication to MVC - asp.net

I was assigned my first ever MVC 5 projet, it is a simple Lending System with lots of CRUD operations which is almost done except that I have not implemented user authentication to the app yet.
My project has 4 layers:
1. App.Web - mvc web app
2. App.DataAccess - crud repositories
3. App.Common- my edmx/entities and interfaces
4. App.Business - services / logical operations
Now I just need to add user authentication to complete my project. Just a simple individual user account but I need to implement user roles. I do NOT need any other api login feature (facebook, google etc). But I am too lazy to code this and wanted to use asp.net identity instead. So when I created my MVC 5 App.Web, I checked individual user authentication so everything I need is now referenced in my App.Web but I dont know how to make it work with my application layer.
Is there a way I can use asp.net identity in my web application? How can I do this to fit in my application architecture nicely? Please help!

to understand the structure and customization of ASP.NET Identity you can create empty project on visual studio and download this package from NuGet.
Install-Package Microsoft.AspNet.Identity.Samples -Pre

If your project is not too big I mean if have just some simple User roles and Login/Log out system ,so I recommend you to use ASP.NET membership system.it is very easy to manage user's and roles.Please take a look into the following article:
Introduction to Membership

Related

ASP.NET Core Identity - where is Account Controller and Folder

I am new to .NET Core and wanted to ask about Identity.
I bought a book and followed all the instruction. It is very simple to set Identity the way the book describes.
Create an Account Controller, LogIn, Logout views etc...
But when I create a new project with Visual Studio with Individual User Accounts selected.
I can't find the Account Controller folder. There is an Areas folder but almost empty. Areas\Idnetity\Pages\_ViewStart.html.
I checked hidden files etc, but couldn't find Account or Identity Folder.
The login link is like this
https://localhost:44313/Identity/Account/Login
Identity is working but where are the codes?
As this entry states:
In ASP.NET Core 2.1 we can now ship Razor UI in reusable class
libraries. We are using this feature to provide the entire identity UI
as a prebuilt package (Microsoft.AspNetCore.Identity.UI) that you can
simply reference from an application.
Notice that you are asking this feature to be effective by adding .AddDefaultUI(UIFramework.Bootstrap4) to ConfigureServices method.
If you still love to scaffold the Identity as old days, use this cli command:
dotnet aspnet-codegenerator identity --useDefaultUI
For more information on scaffolding options visit here.

Asp.NET and Asp.NET Core Identity model over the same database

I have two applications, one in asp.net and the other in asp.net core. I want to share a common database, as well as the same login. Ie, a user can register via asp.net application, and then their identity will be shared with asp.net core application.
Is this possible? I notice that each have their own identity models, and I am looking for a way of sharing this, ie. some documentation to resolve this.
Looking for:
- Is this possible?
- Documentation and more information on implementation (how to)
I am resolving by use of Identity Server, which both applications will hook into. Will just take a bit of re-jigging.

Configure database for MVC authentication

I've been Googling terms like
configure database for mvc authentication
But I can't find anything from this decade that relates to my configuration.
I've created an MVC application using .NET Framework 4.6 with authentication support (database first). Now where do I find step-by-step instructions for creating the database tables and configuring MVC to use them?
Thanks for any tips!
The correct thing to google for is 'ASP.NET Identity'.
If you generate an MVC app straight from one of the templates it will generate a number of classes to handle security and identity.
One of these classes will implement interface IUserStore. The class provided will inherit from Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser>, and uses Entity Framework to check the database if the tables exist, and create them if they are not there.
If you are uneasy about giving your application enough privileges to modify your data schema (ew!), you can create your own class that implements IUserStore and plug that into the system.
It's a big topic, but hopefully this is enough to get started with.

No Individual User Accounts auth option in ASP.NET Core Web API template

I am a bit confused as to why there is no Individual User Accounts authentication option in the latest ASP.NET Core Web API template.
Is it still possible to implement individual user accounts the way that the MVC template does or would it not make sense?
Let's say I am creating a stand-alone web API that is going to have all of my business logic and data layer that accesses the database which has the AspNet Identity tables. I plan on making calls to this API w/ an MVC app.
I know one way of doing this is to create an asp.net MVC app w/ individual user accounts auth and simply build the API right within the MVC app using a controllers/api folder. However, I don't want to do it this way because I want the API to be its own standalone project that can be hosted on a completely different server and accessed by multiple applications, not just an MVC app.
Can someone lead me in the right direction on how authentication typically works in this scenario since there is no template?
Individual User Accounts authentication option for the ASP.NET Core Web API is available in .NET Core 2.0 Preview 1.
Unfortunately .NET Core 2.0 Preview 1 isn't available in VS 2017 release.
But you can install Visual Studio 2017 Preview (you can use it side-by-side with VS 2017 stable version) :
I think you can use IdentityServer4 which allows implementing single sign-on and access control for ASP .NET Core Web APIs using protocols like OpenID Connect and OAuth2. It offers integration with ASP.NET Core Identity and Entity Framework Core.
You will need to install to the following nuget package:
Install-Package IdentityServer4
and add the IdentityServer middleware to the HTTP pipeline:
app.UseIdentityServer();
You can find several quick start samples here or follow this article.

How to setup RIA Services to use an existing ASP.Net membership base

I'd like to make an OOB Silverlight app based on the Silverlight Business Application template in Visual Studio. The template uses the default ASP.Net membership provider. I understand how to use that to add users and roles, etc. I've found plenty of tutorials on that. What I'd like to be able to do, is configure the Silverlight template so that it uses an existing ASP.Net membership base. We'd like this app to have a companion website (ASP.Net based).
To clarify: We've been able to setup an ASP.Net website and have created a SQL database with the required tables (aspnet_Users, aspnet_Membership, etc.). I'd like to configure a Silverlight app to access the same users and roles that are in those tables.
Can anyone help me out in terms of what I'd need to put in the Web.config? Do I just need a connection string? I'm new to ASP.Net authentication, but I'd rather use what ASP.Net gives me out of the box than have to write my own authentication service. I feel like this should be really easy, and is just a matter of pointing the Silverlight app in the right direction.
I'd like to use Silverlight 5 and .Net 4.5 if I can but I don't mind using an older version of either if it makes things easier.
You can just point the connection string to the existing database.
From this answer:
You can point your connection string for authentication to a database that all application can access.
So if you have the default database that .NET creates, you can point your other application to that as well for authentication.

Resources