In Visual Studio 2010 (VS2010) when you create a new Web Application Project using the default Web Template “ASP.NET Web Application” it creates an Account folder with the files Login.aspx, Register.aspx and ChangePassword.aspx.
These are files/pages for ASP.NET Membership which is ASP.NET’s built-in user handling. I have never used Membership before but have been curious to, so I saw this as my cue to do so. However since I’m running MySQL as my database server I knew I had some extra installing and configuring to do.
Now several hours later I have finally figured out what I needed to do…
1) Install the latest version of MySQL Connector/NET. Visual Studio support is from version 6.3 which is currently only available in beta, current version when writing this is 6.3.2 beta.
2) Use the MySQL Website Configuration Tool, follow instructions found by clicking this link. This tool will modify necessary configuration files (have not checked which, maybe only web.config) to use MySQL Membership, Roles, User Profile and/or Session State.
Important: (this took me quite some time to figure out) the MySQL Website Configuration Tool icon only shows up in the Solution Explorer if you create a Web Site Project in VS 2010. It does not show if you create a Web Application Project. I have reported this as a bug to MySQL.
The only workaround I found to use a Web Application instead of using a Web Site was to create a temp Web Site project, run the MySQL Web Configuration Tool and then use copy and paste to move changes from web.confg to my Web Application Project. I have provided these changes at the end of this post.
I am running Windows 7 64-bit, Visual Studio 2010 and MySQL Connector/NET 6.3.2 beta, but according to this thread other people with other versions of VS seems to be having the same problem.
These are the changes that are made to web.config:
<remove name="LocalMySqlServer" />
<add name="LocalMySqlServer" connectionString="server=localhost;User Id=root;database=users;password=xxx" providerName="MySql.Data.MySqlClient" />
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
<remove name="MySQLMembershipProvider" />
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=188.8.131.52, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="MySQL default application" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enablePasswordRetrieval="True" enablePasswordReset="True" requiresQuestionAndAnswer="False" requiresUniqueEmail="False" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
<remove name="MySQLProfileProvider" />
<add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=184.108.40.206, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" />
<roleManager enabled="false" defaultProvider="MySQLRoleProvider">
<remove name="MySQLRoleProvider" />
<add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=220.127.116.11, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" />
Awsome – all I needed was the web.config changes and you’ve posted them. I can’t get the config tool to show in VS2008 or VS2010 with the 6.3.2 connector either with a new website or web application.
So glad I can now use MySql session management.You’ve saved me hours. Thanks 🙂
Having problems with VS2010 membership with MySql
I am using vs2010 with MySql as the DB. I have configured the MySql membership with the configuration tool, I can go to Project/ASP.NET configuration menu option and manage roles and users, but when I tried to do it from the web site it fails, I cannot register any new user or log in with the user that I created from the admin menu. I have follow your instructions and here is my web config. Please help
Hi, I’m having the same problem that Glover has. I used the configuration tool with VS2010 to use MySQL as database. It creates sucessfully the my_aspnet tables on MySQL and trough the configuration menu I can add and remove users and roles with sucess. However through the website (aspx or cshtml pages) I can’t register or log on with any user. There must be some problem with AccountController. I’m using ASP.NET MVC 3. Please help :S
The MySQL web configuration tool was fixed, but it has broken again. I’ve reported the bug (again) and asked them to update the documentation to include what the tool does so we can write the web.config by hand for the next time it breaks 😉
I’m only interested in storing the session data inside MySQL but your xml doesn’t mention anything about sessions? Is the session stuff implicit when you include the membership provider.
Anyone know how to store session data only, inside MySQL?
Just had a quick look at your bug report. I made another bug report here http://bugs.mysql.com/bug.php?id=60445 and this one is also related and have some more info on a workaround if you check the comments (have not tried it myself) http://bugs.mysql.com/bug.php?id=60723
As you write in your bug report, this seems to be something that breaks on a regular basis… 🙂
Great information, but…
running VS2010 SP1 MySql ASP Client 6.4.4
I get this when I try to Register a new user. I first tryed to login with my user i created under SQL and it failed as expected. So I went to register that user again and recieved the following note.
CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Question for the security question, this is required if your membership provider requires a question and answer.
If you create website and connect to MySQL, the MySQL configuration tool shows up. Then open existing web application and it stays there No cut and paste needed.
One question, How do I populate data from mySQL database based on the user that logged in? You would think you could use login id in WHERE clause in the query.
For example, I would like to populate a list with phone numbers of the user logged in from a mySQL database.
Thanks a lot! Ample content!