2

I'm using ASP.NET MVC 3 to built my site (former PHP programmer), using Entity Framework and I wish to integrate the built-in membership support. Although I've read lot of questions and tutorials I couldn't figure out wish approach should I use when using MVC and EF.

I read about the MembershipProvider but it seems like a ASP.NET web-forms related...

Which technique should I use in order to integrate membership (with many properties, even different sign on ways: FB, twitter etc.) to my site and be able to integrate it with my currently Entity framework data. Note: I've used code-first approach but I don't mind to rewrite it since I didn't got anything special yet.

4

3 回答 3

1

It looks like you will need to implement your own membership provider. Not very easy, but doable. See the MembershipProvider class. This implementation might help you as well.

于 2012-07-03T02:50:36.623 回答
1

How do you mean to your current EF data? The two generally can remain separate. Auth is a security concern, your EF classes are a business domain concern, so the two generally can remain separate and asp.net membership will run in its own separate database.

The question now is iif you want all these tables in the same database (which many do) in that case use Ambers suggestion below with aspnet_regsql.exe although you'll need to update the connect string for the membership and role provider. In this way using EF code first you can use your existing EF connection string (you can't do this however with database first and the edmx connect string)

To configure the db connection string for membership: http://msdn.microsoft.com/en-us/library/6e9y4s5t.aspx

于 2012-07-03T14:10:18.060 回答
0

You can use standart MembershipProvider in ASP .NET MVC 3 too. It doesn't use EF connection, it works with database in its own way.

You should prepare database with aspnet_regsql.exe, and implement your logic - authentification, creating new users, adding new roles for them, changing password and so on. In general, the best way is to study Test Internet Application in VS.

If the functions of standart MembershipProvider isn't enough for you, you have to write your own implementation.

于 2012-07-03T08:04:19.790 回答