How to use SimpleMembership and OAuth with mySQL or any database you want and have the user’s primary key (UserId) set to unsigned bigint or any datatype in a nutshell:
1) Download the assembly source code.
SimpleMembership source code is located at http://aspnetwebstack.codeplex.com/
Steps in details:
- Download the source code.
- Open Runtime.sln (solution file).
- Isolate the projects we need. Delete all projects except:
2) Now it is the part where you rewrite the source code. You can skip this for now, and do it after all the other remaining steps are done. Just to make sure you can compile first and assign it to your project.
Look for all int related to the userId via Find & Replace or however you feel more comfortable with, and replace it with long. Also, look for the scripts that generate the tables in database and change accordingly, rewrite the database wrapper if necessary, etc… Now it is all up to you. You can do whatever you want.
For example, a method signature:
would be changed to:
3) Resigning the assembly. Do the following to all 3 projects:
- Right-click on the project, and click Properties.
- Click the Signing tab.
- Keep the Sign the assembly check box enabled.
- Specify a new key file. In the Choose a strong name key file drop-down list, select <New…>.
- In the Create Strong Name Key dialog box, enter a name and password for the new key file, and then click OK.
- Disable Delay sign only.
4) Now, notice that there are missing references (WebPages, etc..). You can use nuget to add the references back. Go to Package Manager Console window (menu View / Other Windows) and run the respective command for WebMatrix.WebData and Microsoft.Web.WebPages.OAuth projects, in this order:
PM> Install-Package Microsoft.AspNet.WebPages
And run this one for Microsoft.Web.WebPages.OAuth only:
PM> Install-Package DotNetOpenAuth
IMPORTANT: When installing the packages, do it in the order I specified.
You can change the project by clicking on Default project drop down list in the Package Manager Console window.
Now recompile. Then, just replace them in your application. I’ve used an MVC 4 project (.Net 4.5).
With the introduction of a new WebSecurity API that delegates to the SimpleMembership provider, it became easier to handle authentication, and now you can use any datatype you want, bigint (long in c#), uint, etc…
Hope this has been helpful to you.