安装 MySql Membership 用 Visual Studio 2010
2013-01-15 17:41 音乐让我说 阅读(428) 评论(0) 编辑 收藏 举报Introduction
This article will help in setting up the MySql membership provider with Visual Studio 2010.
Background
Membership provider will help in automatically setting up the login functionality that comes with .NET Framework.
Prerequisites
- MySql server should be installed on the local machine or on the remote machine with which you have access.
- We need a database to which we will connect to test the membership provider after configuring.
Following Steps Will Help in Setting Up the MySql Membership Provider with .NET
- Download and install the fully-managed ADO.NET driver for MySQL from here version 6.3.4+
- You might have to close down the Visual Studio development env. before starting the install.
- After installation, you can confirm that the MySql assemblies are present in C:\WINDOWS\assembly folder like in the image below:
-
Configure a database in MySql server, I have created a "Test" database on localhost, User as "root" and password as "rootpassword", I will be using these same credential in connection strings configuration.
- Put the following code for connection string in web.config:
<connectionStrings> <remove name="LocalMySqlServer"/> <add name="LocalMySqlServer" connectionString="Datasource=localhost; uid=root; Pwd=rootpassword; Database=test;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
- Put the following code for Membership provider, Profile Provider and Role Provider. Check that you refer to the correct connection string name in the below config.
<membership defaultProvider="MySqlMembershipProvider"> <providers> <clear /> <add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web,Version=6.3.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" autogenerateschema="true" /> </providers> </membership> <profile> <providers> <clear /> <add type="MySql.Web.Security.MySQLProfileProvider, MySql.Web,Version=6.3.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" name="MySqlProfileProvider" applicationName="/" connectionStringName="LocalMySqlServer" autogenerateschema="true" /> </providers> </profile> <roleManager enabled="true" defaultProvider="MySqlRoleProvider"> <providers> <clear /> <add connectionStringName="LocalMySqlServer" applicationName="/" name="MySqlRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web,Version=6.3.4.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d" autogenerateschema="true" /> </providers> </roleManager>
- Open machine.config from "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG" in the connection string section, add the following code:
<connectionStrings> <add name="LocalMySqlServer" connectionString="Datasource=localhost; uid=root; Pwd=rootpassword; Database=test;" /> </connectionStrings>
-
In same machine.config, check and modify the providers for Membership, Profile and Role also check that connectionStringName attribute points to correct connection string name.
Don't delete any of the config settings that are present by default in these provider sections, just add the following lines between provider sections.
<membership> <providers> <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" autogenerateschema="true"/> </providers> </membership> <profile> <providers> <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" /> </providers> </profile> <roleManager> <providers> <add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.3.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" /> </providers> </roleManager>
- Go to Visual Studio, click Project->ASP.NET configuration:
- ASP.NET Web Application Administration will open in a new window, click on security tab you can now create User, Roles and Access rules
- You can also check with the database in MySql that has been configured with the project with the list of *aspnet* tables, these are auto generated in the database.
转载自:http://www.codeproject.com/Articles/117157/Setting-up-MySql-Membership-with-Visual-Studio-201
以下是我的操作截图:
谢谢浏览!
作者:音乐让我说(音乐让我说 - 博客园)
出处:http://music.cnblogs.com/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步