How do add/integrate SqlMembershipProvider in existing MVC 3 project? - c#

On creating a new MVC project, Visual Studio take cares of SqlMembershipProvider if it is a non-empty project. Visual Studio creates a Database and all necessary Tables.
But, I have an existing MVC 3 project and I would like to add/integrate SqlMembershipProvider.
How can I add SqlMembershipProvider and create all needed Tables in my existing Database?

You need to run
Aspnet_regsql.exe ( this creates the necessary tables into your existing database)
Take a look here:
What's difference between windows and forms authentication in asp.net mvc 4?
YES, ignore the sections of code that refer to comparison for windows and forms authentication. However, it should serve as useful information on SQLMembershipProvider which uses the Membership and MembershipUser classes to provide these membership services to a ASP.NET application.
Aspnet_regsql.exe
http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider(v=vs.90).aspx

You can use the Microsoft ASP.NET Universal Providers nuget package
ASP.NET Universal Providers add provider support in ASP.NET 4 for all
editions of SQL Server 2005 and later and to SQL Azure. If you use
these providers to develop your application, the application will be
ready for cloud environments like Azure. Other than supporting
additional storage options, the providers work like the existing
SQL-based providers, so that you can easily switch an application to
use cloud storage via SQL Azure.
And for this great Hanselman's post
The configuration for these providers is the same as the existing
SqlMembershipProvider class, but the type parameter is set to the type
of the new providers, as shown in the following table:
SQL Provider Types -> Equivalent Type for Universal Providers
System.Web.Security.SqlMembershipProvider
-> System.Web.Providers.DefaultMembershipProvider System.Web.Profile.SqlProfileProvider
-> System.Web.Providers.DefaultProfileProvider System.Web.Security.SqlRoleProvider
-> System.Web.Providers.DefaultRoleProvider (Built in provider) System.Web.Providers.DefaultSessionStateProvider

Related

How to migrate ASP.NET Web Forms application from Membership to ASP.NET Identity 2.0?

I have an application which is in .NET Framework version 4.5. It uses Web Forms and EntityFramework 6.1.1.
The EntityFramework's Context object is of type ObjectContext. I'm using ASP.NET Membership(the MembershipProvider is customized i.e Custom Membership) for managing the user account related operations.
I want to migrate my Web Forms application to ASP.NET Identity.
According to http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity article I think I have to do the following things to migrate to the ASP.NET Identity:
Convert the ObjectContext to DbContext(and correct the related codes)
Create the new tables needed for ASP.NET Identity and do the data migration.
Redefine the account section codes and other dependent codes as needed to match the business logic.(optional)
I have few questions in my mind:
1) I have customized the membership User table and there are several custom foreign keys associated with the User table. Will it still be feasible to migrate to the Identity system without losing any data?
2) As I'm using EntityFramework so DbContext is needed to migrate to Identity system. Can I use ObjectContext for ASP.NET Identity migration?
3) I'm NOT using all the Membership tables as listed at http://i1.asp.net/media/48109/image006.png?cdn_id=2014-11-11-001. (i.e aspnet_Applications, aspnet_Membership, aspnet_Paths, aspnet_PersonalizationAllUsers, aspnet_PersonlizationPerUser, aspnet_Profile, aspnet_Roles, aspnet_SchemaVersions, aspnet_Users, aspnet_UsersInRoles, aspnet_WebEvent_Events)
But I am using Application, User, Role, UserInRole, Profile tables only. Can I still migrate these table in order to use the ASP.NET Identity?
I'm ready to provide more information you may need to understand my current scenario.
I'm looking for the correct steps to migrate to Identity, any caution I need to take care, any hurdles I will face? Any help is highly appreciated.
Dave Paquette wrote this http://www.davepaquette.com/archive/2013/12/30/so-you-inherited-an-asp-net-web-forms-application.aspx
This may be the answer to your problem. Once you have integrated your Web Forms project to MVC, there are plenty of guides online to integrate the new Identity 2.0.

Asp.Net MVC 5 Identity Create Database Admin Interface

I'm working on a new asp.net mvc 5 app for a small company and am trying to figure out how to create the membership database using the new asp.net Identity system. I thought there might be an admin interface I can use which would create the database and allow me to add a few users/roles. Is there an admin interface for this task or another way I will need to accomplish it? Are there any tutorials on doing something like this? All I have been able to find so far has dealt with external logins using other providers such as Facebook or Google.
I'm pretty sure that it's based off of Entity Framework Code First. When you create the db context, it should create the table for you automatically.
http://msdn.microsoft.com/en-us/data/jj193542.aspx
MVC 5 Template with VS2013 use ASP.NET Identity instead of membership provider and has no admin interface. After creating a new MVC5 project in VS2013, run the website. Once you register the first user on the web interface a local database will be created under the App_Data folder. You could rename the connection string to point to other database and register user again to create the database. To add users you could enable migration and use the seed method.
Scott Allen published a great video which might help you to understand ASP.NET Identity more
http://pluralsight.com/training/courses/TableOfContents?courseName=aspdotnet-mvc5-fundamentals&highlight=scott-allen_aspdotnet-mvc5-fundamentals-m2-katana*8#aspdotnet-mvc5-fundamentals-m2-katana

Authentication and role authorization in ASP.NET MVC 4

I'm new to ASP.NET MVC 4 framework, before I developed .NET web apps using ASP.NET Web Forms.
In my new project (I'm updating an existing Web Form project) I need to implement Form authentication and role based authorization to pages and functionalities.
Following some articles and StackOverflow answers I'm trying to use SimpleMembershipProvider but I'm finding several difficulties to configure it and in integration with my existing DB.
In particular cannot use my existing user accounts table...
I'm using SQL Server 2005 and now I'm upgrading from Linq-to-SQL to EntityFramework.
Can you suggest me the best way to implement authentication and role authorization in ASP.NET MVC4?
It depends how custom you need:
1) Try something, that exists already. As long as you're using EF, you may try https://efmembership.codeplex.com. Haven't tried it, but from first look, looks reasonable and configurable. There are also other MembershipProvider implementations on nuget gallery if previous one does not fit.
2) If really nothing fits into your scenario from existing in nuget gallery, implement membership provider by your self. Example may be here: http://blog.ianchivers.com/2012/03/entity-framework-custom-membership.html or there even video how to do it: http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-custom-membership-provider

WCF Service authentication and authorization

I have the requirement to setup authentication and authorization on a WCF Service, right now the service is created and working but no authentication.
There is also the need to authenticate existing users and passwords that are being stored in a SQL database and are already used by another web application, but since I do not have the source code for it, and being still adjusting do .NET I am having some dificulties.
I can read the database and found several aspnet_ tables in the database such as aspnet_Users, aspnet_Roles etc that so far seem to match with the ones used in the web application.
My question is how can I easily implement authentication and method authorization using the existing database.
Please note that I do not have access to the web-application source code.
Thanks.
MVC uses the standard ASP.Net membership provider. If you click the Log On button/register link - you can add a user. ASP.Net will create App_Data\ASPNETDB.MDF containing the membership information. You can move ASPNETDB.MDF to a remote DB server, but you must use the Membership provider schema/DB (unless you write your own provider).
A few MVC links to get you started.
http://www.asp.net/mvc/tutorials/older-versions/security/authenticating-users-with-forms-authentication-vb
http://weblogs.asp.net/fredriknormen/archive/2007/11/25/asp-net-mvc-framework-security.aspx
http://blog.wekeroad.com/blog/aspnet-mvc-securing-your-controller-actions/
The default authentication/authorization configuration added use ASP.NET standard membership and role manager service provider( the local SQL Express one). If your existing database(for user login) is also ASP.NET standard sql membership database, you can simply change the connection string of the membership section. Otherwise, you might need to create a custom membership provider which uses your own database tables for user authentication.
Implementing a Membership Provider
http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx
Building Custom Providers for ASP.NET 2.0 Membership
http://msdn.microsoft.com/en-us/library/aa479048.aspx
Really no easy way to achieve your requirements. Here is the library you can use and follow stricktly steps described in this blog to setup authentication with SQL Membership provider for WCF services.
In my case I did small update to the library. I've commented out line of code
//if (!IsAnonymousAllowed)

What's similar to the Membership Provider in Winforms? [duplicate]

The Asp.Net membership provider has some clear uses in a web app. I am thinking about trying to leverage some of the features in a windows application (more specifically WPF). Does anyone know if it is possible to use the core features in a windows app? I am mostly just looking for it to create my database tables, and maintain users, roles, and profiles. I obviously do not need to use the built-in web controls (e.g. Login).
Yes. Membership, roles and profiles are all features of Visual Studio 2008 Client Application Services (Services tab of a project properties)
http://msdn.microsoft.com/en-us/library/bb384297.aspx
http://channel9.msdn.com/posts/DanielMoth/Client-Application-Services-with-Visual-Studio-2008/
I have a winform app that talks to DotNetNuke (DNN). DNN uses the Asp.net membership provider, so the source will work for other apps that use that membership provider as well. It's a very simple app, so you should be able to read the source easily.
http://www.datakido.com/downloads/Token/ViewInfo/ItemId/3
You should be able to adapt the source to work with WPF.
Yes, you can.
All the configuration can be done within app.config instead web.config of asp.net.
Make sure that you are creating a 3.5 application (WPF 4 won't work yet) - Then you must import the reference System.Web. This will allow you to use "using System.Web.Security;" like you normally would in a web app... now you can access stuff such as Membership.CreateUser()
Your app.config file has to be configured for your provider along with a connection string.

Categories