We have an old asp.net(web.forms) membership database(aspnet.users,membership,roles,etc..)
how can I integrate this with new mvc application.
I checked this answer but this uses a completely new database, and according to this post , it's gonna be a pain. I'm wondering whether this solution would work. I will of course hook up our custom user identity. I just need the core or main steps to do this.
Thanks..
Take a look at the answer to this question. It demonstrates how to implement IUserStore, IUserPasswordStore, IUserEmailStore and IPasswordHasher to consume an exising ASP.NET Membership database in ASP.NET Identity.
Related
I have followed this guide https://github.com/aspnet/JavaScriptServices to create an asp .net core 2 aurelia project.
But I would like to add identity to this project but I can't find a good guide how to do it...
Anyone who has done this or have an idea where I can start?
Best regards
Andreas
Edit: since I felt this question requires more explanation, I wrote a blog post and a sample on GitHub.
Depending on how far you want to go down the rabbit hole, you could either:
Reimplement the whole ASP.NET Core Identity UI in Aurelia.
Have the default implementation of Identity in MVC.
Have something in between, like have login only implemented in Aurelia and the rest (registration, forgot password, management, etc) implemented in MVC.
For most of my projects, I simply create a new ASP.NET Core MVC app with Identity and then add Aurelia to it (within the same or separate project). Security is hard and it's easy to mess something up. If you leave the default Identity implementation, you can serve Aurelia app via default route (/home/index) and have [Authorize] attribute on the controller or action method to require users to log in before accessing it.
At one point I was thinking about #1, to create a sample app (or even a .NET Core template) with entire Identity UI re-implemented in Aurelia and blog about it, but of course, time was an issue and I never started it.
So, my suggestion is to go with #2.
If you are on ASP.NET Core 2.1 (and you really should upgrade to it, since 2.0 end of life comes in a few months), there are some Identity changes that might help you. Identity in 2.1 is implemented as a separate Razor Class Library, which is a new feature in ASP.NET Core 2.1.
You can find more details about how to scaffold Identity to existing ASP.NET Core projects in the documentation.
I am a new to MVC and I need some assistance attaching my account details from my SQL database to the account controller.
When you create a MVC project you have the account setting all set up.
I have attached a database and would like to use my database to add/remove users.
How do I go about modifying the current account code to use my database users?
Thanks
Did you create your MVC project from a template? This is always a good place to start I found. It gives you a nice road map to understand how MVC works. I have started from here on a number of projects and just built out from here.
Open a blank web project in VS and then go to the Package Manager then copy this line in the window: http://www.nuget.org/packages/Microsoft.AspNet.Identity.Samples/2.0.0-beta2
There are other templates like this. But this is a good place to start. It primarily deals with Authentication because of the Identity piece but it has th4e basic MVC bit in there that is quite simple.
One way is that you can add field to the userViewModel. This also need to be done for the applicationUser class and then these will bubble through to the tables.
I am not sure if this is what you want but it seems that you are using template with authentication selected. If that is the case you will have asp.net identity authentication and authorization as built in feature in your template. If you don't want to use that in-built authentication you can select none for authentication while creating project and then you can implement you custom authentication in project. For custom authentication you can follow below links
http://www.dotnettricks.com/learn/mvc/custom-authentication-and-authorization-in-aspnet-mvc
https://www.codeproject.com/Articles/1111522/Custom-Authentication-and-Authorization-in-MVC
I have implemented working solution of custom nhibernate membership provider to use in mvc3 projects. It was separated web.membership project which covers all that I need in my web apps.
Now I want to switch to mvc4 and I have noticed that it uses System.Web.Security.FormsAuthentication class in the Account controller, also it uses the WebMatrix.WebData.Security class.
If anyone know useful tutorials on how to write custom (nhibernate or not) simple membership provider it would be great.
Thanks
The System.Web.Security.FormsAuthentication has absolutely nothing to do with Membership. This is used to emit forms authentication cookies and this was class was present since ASP.NET 1.0 and is not specific to MVC4.
The SimpleMembership Provider is indeed a new custom membership provider that was designed for ASP.NET MVC 4 and it uses SQL Server to query the database.
You could still use your custom membership provider in MVC4 without any problems. The Simple Membership Provider was created in order for users that do not have any existing membership provider code to get started with MVC. Since you already have a working implementation with NHibernate I would recommend you using that. The Simple Membership Provider was not intended to be customized that way.
I am exploring the possibilities of ASP.NET MVC in the example webapplication of Visual Studio the WebMatrix.WebData.WebSecurity is used for Membership (creating accounts, and specify that a user is logged in to view a specific page etc.). But after some searching I found that there is also a System.Web.Security.FormsAuthentication class that can be used for Membership.
Does anybody know the differences/pro's and cons between these two classes? And when to use WebSecurity and when to use FormsAuthentication? (and maybe a clear example of FormsAuthentication)
Thanks in advance
WebSecurity was introduced in WebMatrix 2 and ASP.NET MVC 4. It relies on the SimpleMembershipProvider. Under the covers it uses FormsAuthentication to manage cookies. So I guess that if you are starting a new project you would opt for the new model if this model fits your needs. Bare in mind that the SimpleMembershipProvider exposes less functionality than the original provider.
The original membership provider uses the SqlMembershipProvider which in turn uses plain ADO.NET to query the database.
The SimpleMembershipProvider uses the new Database class introduced in WebMatrix to query the SQL database.
The main differences between old ASP.NET Membership provider and SimpleMembershipProvider are explained in this good article - http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx
It is better to use SimpleMembershipProvider (WebMatrix.WebData.WebSecurity) than old ASP.NET Membership Provider (or Universal Providers)
I've been reading about overriding the Membership Provider and the Role Provider. I think this is what you need to do when doing Asp.net Form projects. Is this also the way to go with Asp.net MVC projects or there is a better way to do so?
Thanks :)
You could use the built in membership provider
http://dotnetaddict.dotnetdevelopersjournal.com/aspnet35_membership.htm
or create a custom one
How do I create a custom membership provider for ASP.NET MVC 2?
http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider
Yes, ASP.NET MVC uses the Membership API by default. However, you can always use your own logic if you want to, but most functionality for the Membership API is in there already.
You'll need:
A custom MembershipProvider
If you use roles, a custom RoleProvider
If you use profiles, a custom ProfileProvider