MySQL and .Net 4 Membership...

Soldato
Joined
28 Aug 2006
Posts
3,003
Well MS certainly didn't make this a simple task.

Just trying to get my head around the many different google answers.

Has anyone had to go down this route?
 
Associate
Joined
1 Dec 2005
Posts
803
Oh I know there are differences and reasons you might not want to use SQL Express. But do they apply in this scenario? That is the question ;)

It always helps to follow the 'happy path' if you can.
 
Soldato
OP
Joined
28 Aug 2006
Posts
3,003
Any reason you're not using SQL Express?

Not sure my hosting supports that. They have a MS SQL server, with 1 free DB. But additional DBs cost.

I'd like to go down the MySQL route as thats not limited.

I'm surprised that Membership has specific MS SQL stuff in it. Surely they should have decoupled it from the DAL.

I tried the earlier example, for .net 4 and MVC 4, but it broke things. I'm guessing I need a few extra classes for Membership and Roles.

They don't like to make things simple :S
 
Soldato
Joined
17 Nov 2005
Posts
3,052
Location
Swindon, UK
In your .Net project, if you drag the 'login' from the toolbox, click the little '>' and click on 'Administer Website', you should end up at the 'Web Site Administration Tool'.

Click on the 'provider' tab and there are links there to manage a 'MySQL' DB.
 
Soldato
OP
Joined
28 Aug 2006
Posts
3,003
I don't think its as easy as that. From my googling, it sounds like the default membership classes have some specific MS SQL code. So im guessing i'd need to implement some replacement classes to generalise the SQL specific methods.
 
Associate
Joined
1 Dec 2005
Posts
803
That sounds odd, have you tried starting a bare bones basic web project with the provider? It might be some other code or configuration causing problems.

If all else fails, you can always write your own providers. Use ILSpy to borrow some code from the original MS providers to get started (or go it alone if you're feeling brave).
 
Soldato
OP
Joined
28 Aug 2006
Posts
3,003
It breaks on UsersContextobject, which it says can't be found.

UsersContext is a class derived from DbContext which is defined in the Models\AccountModel.cs file.

I'll keep plugging away at it, when time allows.
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,325
Location
Derbyshire
Soldato
OP
Joined
28 Aug 2006
Posts
3,003
Thanks, downloaded the zip you did and will give it another go during the week.

Thanks for everyones' input. Greatly appreciated.
 
Soldato
OP
Joined
28 Aug 2006
Posts
3,003
I just tried the guide I/Shad posted and it works fine.

  1. Install MySQL connector .NET
  2. Create a membership database in MySQL
  3. Update your connection string in web.config to point to your new DB
  4. Go to Project > ASP.NET configuration in Visual Studio and create a user under the security section
  5. Do all the account fixes from the guide
  6. Launch your project and login

Here's a working zip of love with it all done:
https://dl.dropbox.com/u/41110491/Web.Membership.MySQL.zip

Enjoy :).

I did exactly as said, and I still get the "UsersContext" error. So I compared my solution with your zip.

It seems that my default MVC4 solution adds Filters > InitializeSimpleMembershipAttribute.cs which is missing from your zip. So I have now removed his file and it compiles again.
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,325
Location
Derbyshire
Ahh. Looks like they made a whole load of changes in MVC 4 authorization with SimpleMembership. The guide for MySQL basically takes you back to the MVC 3 membership system (but still letting you use MVC 4 for everything else). I deleted the file as well to get it to compile.

Least it works :)
 
Back
Top Bottom