Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Implement ASP.Net Membership in MVC Project?

I am new in ASP.NET Membership. And I want to implement ASP.NET Membership in ASP.NET MVC project. I am not sure is it possible or not.

Whenever we going to create MVC application at that time we found option for change authentication(no authentication, identity authentication, organization etc.). I've select identity authentication and get those tables in my application. look attached.

enter image description here

But I don't want ASP.NET Identity table and functionality.

I want ASP.NET Membership table and functionality(user CRUD operations, assign role, change user password etc) look attached.

enter image description here

I have found the way for create ASP.NET Membership table in SQL Server.

  1. Go to directory C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 Click
  2. aspnet_regsql.exe. You will see the following screen.

But do you remember whenever we create MVC application with identity then they provide registration and login functionality inbuilt(no need to write code for that) yeah same, I want in ASP.NET Membership too.

Your answer will appreciable! :)

Thanks in advance :)

like image 543
Jatin Gadhiya Avatar asked Oct 03 '15 15:10

Jatin Gadhiya


2 Answers

If you really want to use ASP.NET membership, the simplest way is to use ASP.NET built-in functionality, because you can use old ASP:NET as part of ASP.NET MVC application.

Another approach is to write these administration pages by yourself. It means to write controller and views. There are more pitfalls with this approach.

Transaction pitfall: If you want to combine the registration with another read/write action to another part of your database, you would like probably use transaction to keep database consistent. But you cannot combine ASP.NET membership function with another code (ADO.NET, Linq-2-SQL or Entity Framework) because database transaction need to be proceed in one database connection. Build in ASP.NET Membership function use custom connection provided by connection string in web.config. Thus transaction is performed on two connections (ASP.NET Membership connection and your connection) and it does work unless you configure your server for distributed transactions. This is not sometime supported by hosting providers.

Finally I have solved this by rewriting the membership providers myself from scratch calling the ASP.NET membership procedures. It solved the problems with two connection and distributed transaction.

Entity Framework pitfall: It is possible that you are going to use Entity Framework in you application. You will probably need to ask for membership in some of your business layer. EntityFramework does not support IDBConnection or DBConnection, but you need to provide EntityConnection. It means Entity Framework use different type of connection that ADO.NET. And calling ASP.NET membership stored procedures from entity framework does not provide you the return code. I solved this issue by creating wrapper in SQL server for every ASP.NET membership stored procedure.

So finally integrating ASP.NET membership into modern ASP.NET MVC application with Entity Framework is really a lot of work. I wouldn't do that for new project. For new project try to use OWIN instead.

like image 104
Tomas Kubes Avatar answered Sep 19 '22 02:09

Tomas Kubes


I am new in ASP.NET Membership.

ASP.Net Membership you mentioned is more than 10 years old. Microsoft has deprecated it. Here is the history -

  1. ASP.Net Membershi Provider (you mentioned)
  2. ASP.NET Universal Providers
  3. Simple Membership Provider
  4. ASP.NET Identity (current version is 2)

Microsoft is moving toward ASP.Net Identity. It is why you cannot find any article regarding MVC and old Membership.

Since you are also new to ASP.Net Membership, I personally recommend to learn ASP.Net Identity. Here is the free course and book -

ASP.NET MVC 5 Fundamentals by Scott Allen

ASP.NET identity from Adam Freeman's book

How to Implement ASP.Net Membership in MVC Project?

You can use AccountController generated by ASP.Net Identity, and replace UserManager with Membership by yourself.

like image 31
Win Avatar answered Sep 19 '22 02:09

Win