6

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 :)

1
  • I don't think it's doable without writing AccountController class yourself Commented Oct 5, 2015 at 16:47

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Hello qub1n.. Thanks for your answer. Really is it not possible to auto generate the controller and view for asp.net membership table into new/existing mvc application?
If it is possible, I don't know how. But I wanted told you that even if you succeed, it will be the beginning of the problems.
Hi, I have a similar problem, I have an existing project based on asp.net membership and another in OWIN. The requirement for me is to log in in the first system and when redirected to other system the user has not to log in again, is that possible to achieve that in some way ? The data from aspnet membership tables are migrated to new AspNet tables but not sure where to start and rewrite the code to make something like shared 'cookie' or shared 'session' to provide that functionality
Check the link Tomas posted on OWIN. One of the clearer and practical explanations Ive seen from MS lately. Thanks Tomas
2

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.

1 Comment

Hello Win... I said I am new in asp.net membership. but not in identity. I am very well know about idenity how work. but i want asp.net membership for some my custom projects. so can you please advice how can i implement this thing without one line of code.
0

Steps 1.Registering Database in .C:\Windows\Microsoft.NET\Framework64\v4.0.30319 aspnet_regsql

2.Add membership default provider in web.config

3.Create register and login model and their corresponding view

4.AccountController

Using Membership.CreateUser(string Username,string Password,string Email) to create new user.

using Membership.validateUser(string username , string password) to validate the entered credentials.

5.On Successful logging in Create Authentication Cookie
create ticket ->using FormsAuthenticationTicket()
encrypt the ticket
create new cookie
add this cookie in Response.Cokies

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.