Use SimpleMembership and OAuth with mySQL and bigint or any database and datatype you want

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.
2) Modify.
3) Resign.
4) Recompile.

SimpleMembership source code is located at

Steps in details:

  1. Download the source code.
  2. Open Runtime.sln (solution file).
  3. Isolate the projects we need. Delete all projects except:
    1. Microsoft.Web.WebPages.OAuth
    2. WebMatrix.Data
    3. WebMatrix.WebData

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:

int GetUserId(...)

would be changed to:

long GetUserId(...)

3) Resigning the assembly. Do the following to all 3 projects:

  1. Right-click on the project, and click Properties.
  2. Click the Signing tab.
  3. Keep the Sign the assembly check box enabled.
  4. Specify a new key file. In the Choose a strong name key file drop-down list, select <New…>.
  5. In the Create Strong Name Key dialog box, enter a name and password for the new key file, and then click OK.
  6. 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.


10 thoughts on “Use SimpleMembership and OAuth with mySQL and bigint or any database and datatype you want

  1. Hello, I’m using your technique to replace the WebMatrix.Data and WebMatrix.Webdata modules so that I can run SimpleMembership against a MySQL DB. Now I am coming up with a key signing error: Could not load file or assembly ‘WebMatrix.WebData’ or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

    1. hi David, it seems that you have skipped a step in my guide. I suggest you start all over again following to the letter, in the exact same order. I have made some changes that should clear out any issues. But if you do have any, let me know.

      1. Oops, I forgot to sign one of the assemblies! Thanks for posting this!


  2. Hi Fabio,

    The link for the source code is broken.

  3. I have followed up to the line:

    “Now recompile. Then, just replace them in your application. I’ve used an MVC 4 project (.Net 4.5).”

    What do you mean by replace them in your application? I am unsure how to reference these files (if this is even correct at all). Thanks!

  4. Thanks for the quick reply! How can i reference them from an outside project? I am having difficulty finding where the .dll file is. If this is not the way to go, do I just build a new project around that solution? Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s