Tutorial :ASP.NET Membership/Role providers for MySQL?



Question:

I am not at all familiar with ASP.NET membership/roles. This is my first time using it, and my first time trying ASP.NET MVC. When I create my first project for MVC, it gives me a lovely template to create an account. I was excited to see that I did not have to do this manually. However, it failed because it cannot connect to SQL Server. I do not have SQL Server, I have MySQL. Is there any easy way I can get this system to use MySQL instead, or will I have to create my own authentication?


Solution:1

Got it figured out! Using version 6.2.2.0 of MySql Connector/Net, follow these steps...

  • Add reference to MySql.Web.dll
  • Change your <membership> in web.config to this:

    <membership defaultProvider="MySqlMembershipProvider">    <providers>      <clear/>      <add name="MySqlMembershipProvider"           type="MySql.Web.Security.MySQLMembershipProvider,                 MySql.Web, Version=6.2.2.0, Culture=neutral,                 PublicKeyToken=c5687fc88969c44d"           autogenerateschema="true"           connectionStringName="NAME_OF_YOUR_CONN_STRING"           enablePasswordRetrieval="false"           enablePasswordReset="true"           requiresQuestionAndAnswer="false"           requiresUniqueEmail="false"           passwordFormat="Hashed"           maxInvalidPasswordAttempts="5"           minRequiredPasswordLength="6"           minRequiredNonalphanumericCharacters="0"           passwordAttemptWindow="10"           passwordStrengthRegularExpression=""           applicationName="/"       />    </providers>  </membership>
  • Run the Project | ASP.NET Configuration tool and click on the Security tab to test
  • Tested on ASP.NET 3.5, MySQL Server version 5.1, Windows XP 64-bit


Solution:2

The original question didn't specify which version of ASP.NET & MVC was used. With the recent release of .NET 4.5 and MVC 4 I hit the same problem as the OP but with the new technologies. This is my quick fix for it mostly the same config as Josh Stodola's answer but with some additional steps.

<membership defaultProvider="MySqlMembershipProvider">    <providers>      <clear />      <add name="MySqlMembershipProvider"           type="MySql.Web.Security.MySQLMembershipProvider,           MySql.Web, Version=6.5.4.0, PublicKeyToken=c5687fc88969c44d"       autogenerateschema="true"       connectionStringName="*NAME_OF_YOUR_CONN_STRING*"       enablePasswordRetrieval="false"       enablePasswordReset="true"       requiresQuestionAndAnswer="false"       requiresUniqueEmail="false"       passwordFormat="Hashed"       maxInvalidPasswordAttempts="5"       minRequiredPasswordLength="6"       minRequiredNonalphanumericCharacters="0"       passwordAttemptWindow="10"       passwordStrengthRegularExpression=""       applicationName="/" />    </providers>  </membership>  

Get the AccountController and Views working:

  1. Delete the MVC 4 AccountController, AccountModels, Account view folder and _LoginPartial shared view
  2. Create a new MVC 3 web application
  3. Copy the MVC 3 AccountController, AccountModels, Account view folder and _LogOnPartial shared view into your MVC 4 application
  4. Replace @Html.Partial(“_LoginPartial”) in the shared _Layout view with @Html.Partial(“_LogOnPartial”)


Solution:3

I've did this with asp.net but I think it could be used for mvc too: hasangursoy.com.tr/aspnet-authorization-authentication-with-mysql


Solution:4

In my scenario, I do not need to connect to MySQL from my .NET web applications. Therefore, I solved this problem by doing two things:

1) Uninstall MySQL .NET Connector (all versions) 2) Inside the Web.Config file, remove all keys that were added after the MySQL installation. (Or else, copy back the original Web.Config file before installation to the .NET web application root folder)

Now, my .NET application is bac


Solution:5

Had to go through something similar.

Here's the official MySql walkthrough that helped me:
Tutorial: MySQL Connector/Net ASP.NET Membership and Role Provider

Note: In my case, the machine.config to be edited was the 32 bit one (they didn't specify which, and editing the 64bit one didn't help).


Solution:6

Click on the menu Project followed by ASP.NET Configuration.

That will create the sql database for you in the Data folder.

Use Visual Studio to look at the data.

Hope this helps.

Edit

I should add that you can then use Ctrl+Alt+S to see the Server Explorer which should then allow you to see your database with its tables and the data.

You shouldn't need SQL installed.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »