Yesterday I blogged about the release of our latest Connector/Net product. Version 5.1, this release includes the addition of a new namespace MySql.Web. This namespace includes implementations of a Membership and Role provider. These providers work together with the membership and role systems in ASP.Net 2.0 to provide a simple mechanism for web developers to add authentication and role support to their web properties.
As we were unable to include proper documentation for these new providers before release, I thought it proper to write down a few thoughts on how these work and how to use them.
1. Provide a connection string
The Connector/Net installer will register the providers in the proper sections of the machine.config file. When registered, they reference a connection string that is non-existent. To use the providers, you must provide a connection string that points to the database you wish to use and must be named 'LocalMySqlServer'. You would provide this connection string in your web.config file. Here is an example:
<add name="LocalMySqlServer" connectionString="data source=localhost;uid=root;pooling=false" providerName="MySql.Data.MySqlClient" />
You can also use the Web Configuration Pages in Visual Studio to select the MySQL Membership and Role providers as defaults for your application. Once this is done, controls such as the Login control will work with MySQL.
2. Understand how the schema is handled
We wanted the providers to work with shared hosting environments where only a single database may be available. To do this, the providers can create or update the necessary schema at runtime. This is handled at initialization time. The provider checks the version of the schema in the selected database. If non-existent, then the appropriate schema is created. If older than current, it will be updated to match what this provider is wanting.
There is a possibility of name collision since your tables and the tables for the providers exist in the same database. This is unlikely, though, since the names given to the provider tables are somewhat unique to their purpose.
We're working on better documentation for these providers and plan to make that available with the 5.1.1 release. Also, we plan to create some articles for our dev zone that will demonstrate how to use these providers.