dotConnect for MySQL Documentation
In This Topic
    ASP.NET Provider Model Support
    In This Topic

    dotConnect for MySQL can be used in the ASP.NET provider model. It allows developers to write better structured applications and easily switch data storage in ASP.NET applications from other media such as Microsoft SQL Server. For detailed information on the basics refer to MSDN whitepaper: ASP.NET 2.0 Provider Model: Introduction to the Provider Model.

    dotConnect for MySQL implements the following providers: Membership, Session State, Role, Profile, Site Map, Web Event, and Personalization. This feature is available in Professional and Developer Editions only.

    This topic provides information on how to set up ASP.NET application to use dotConnect for MySQL as one of these providers. It consists of the following sections:

    Installation and setup

    All providers are contained in the Devart.Data.MySql.Web.dll assembly. You should add a reference to this assembly in your project in order to use the ASP.NET provider model. Another condition for the providers to function properly is existence of certain database objects. Before using ASP.NET providers, you have to run the InstallWebTables.sql script against the database you wish to use. The script can be found in the \Program Files\Devart\dotConnect\MySQL\Web\ASP.NET 2 folder.

    During the installation process dotConnect for MySQL adds new entries into the machine.config file. They are used by websites when the settings are not overridden with a local Web.config file. You can choose to keep the settings in machine.config, in which case they will be used for all web sites, or in Web.config files, where you can set up specific parameters. Note that the default connection string in the machine.config file is incorrect, so you will want to adjust or override it.

    When you redefine an identifier in the Web.config file, you have to add the remove keyword in the appropriate section, as shown below:
      <remove name="MySqlServices" />
      <add name="MySqlServices" connectionString="User Id=root;Host=localhost;Database=Test;" />

    This example demonstrates how to adjust connection string parameters. By default dotConnect for MySQL creates a stub connection string with the name MySqlServices.

    You can also configure your website with the standard Control Panel applet "ASP.NET Configuration Settings". To open it, navigate to Control Panel | Administrative Tools | Internet Information Services, then select a site or a virtual directory, open its properties, switch to ASP.NET, and click Edit Configuration. This dialog provides control over various site settings, including the connection string.

    Membership provider

    The fundamental job of a membership provider is to interface with data sources containing data regarding a site's registered users, and to provide methods for creating users, deleting users, verifying login credentials, changing passwords, and so on. The .NET Framework's System.Web.Security namespace includes the class named MembershipUser that defines the basic attributes of a membership user and that a membership provider uses to represent individual users.

    To access this functionality, use the Devart.Data.MySql.Web.Providers.MySqlMembershipProvider class. It behaves as the System.Web.Security.RoleProvider class (you can read its description in MSDN). The following example shows the Web.config file for an ASP.NET application configured to use MySqlMembershipProvider.

    <configuration>
      <connectionStrings>
        <add name="MySqlServices"
             connectionString="User Id=root;Host=localhost;Database=Test;" />
      </connectionStrings>
      <system.web>
        ...
        <membership defaultProvider="AspNetMySqlMembershipProvider"
          userIsOnlineTimeWindow="15">
          <providers>
            <add
              name="AspNetMySqlMembershipProvider"
              type="Devart.Data.MySql.Web.Providers.MySqlMembershipProvider,
                    Devart.Data.MySql.Web, Version=8.3.215.0, Culture=neutral, 
                    PublicKeyToken=09af7300eec23701"
              connectionStringName="MySqlServices"
              enablePasswordRetrieval="false"
              enablePasswordReset="true"
              requiresQuestionAndAnswer="true"
              requiresUniqueEmail="false"
              passwordFormat="Hashed"
              maxInvalidPasswordAttempts="5"
              passwordAttemptWindow="10" />
          </providers>
        </membership>
      </system.web>
    </configuration>
    

    Note: replace "8.3.215.0" with the actual provider version.

    Role provider

    The fundamental job of a role provider is to interface with data sources containing role data mapping users to roles, and to provide methods for creating roles, deleting roles, adding users to roles, and so on. Given a user name, the role manager relies on the role provider to determine what role or roles the user belongs to. The role manager also implements administrative methods such as Roles.CreateRole and Roles.AddUserToRole by calling the underlying methods in the provider.

    To access this functionality use the Devart.Data.MySql.Web.Providers.MySqlRoleProvider class. It behaves as the System.Web.Security.RoleProvider class (you can read its description in MSDN). The following example shows the Web.config file for an ASP.NET application configured to use MySqlRoleProvider. Note that you can configure MySqlRoleProvider to use the same database and user information as MySqlMembershipProvider in order to use a single database for authentication and authorization information.

    <configuration>
      <connectionStrings>
        <add name="MySqlServices"
             connectionString="User Id=root;Host=localhost;Database=Test;" />
      </connectionStrings>
      <system.web>
        ...
        <roleManager defaultProvider="AspNetMySqlRoleProvider"
          enabled="true"
          cacheRolesInCookie="true"
          cookieName=".ASPROLES"
          cookieTimeout="30"
          cookiePath="/"
          cookieProtection="All" >
          <providers>
            <add
              name="AspNetMySqlRoleProvider"
              type="Devart.Data.MySql.Web.Providers.MySqlRoleProvider,
                    Devart.Data.MySql.Web, Version=8.3.215.0, Culture=neutral, 
                    PublicKeyToken=09af7300eec23701"
              connectionStringName="MySqlServices" />
          </providers>
        </roleManager>
      </system.web>
    </configuration>
    

    Note: replace "8.3.215.0" with the actual provider version.

    SimpleMembership

    SimpleMembership is a new Membership API designed to improve and simplify the use of the built in security in ASP.NET. These SimpleMembership API are implemented as SimpleRoleProvider and SimpleMembershipProvider providers. As their predecessors, they are intended to work with data sources containing data regarding a site's registered users and with data sources containing role data mapping users to roles respectively.

    To support this functionality, dotConnect for MySQL implements MySqlExtendedMembershipProvider and MySqlExtendedRoleProvider classes, which behave as the above-mentioned standard provider classes. You can read our Using ExtendedMembership Provider in ASP.NET MVC 4 Application tutorial to see how to use the dotConnect for MySQL SimpleMembership providers' implementation.

    Profile provider

    The fundamental job of a profile provider is to write profile property values supplied by ASP.NET to persistent profile data sources, and to read the property values back from the data source when requested by ASP.NET.

    Unlike Session State provider, Profile provider is a typed structured data storage. It supports both registered and anonymous users. Profile providers also implement methods that allow consumers to manage profile data sources - for example, to delete profiles that haven't been accessed since a specified date.

    The user profile is accessed using the Profile property of the current HttpContext object. The following example shows the Web.config file for an ASP.NET application configured to use MySqlProfileProvider.

    <configuration>
      <connectionStrings>
        <add name="MySqlServices"
             connectionString="User Id=root;Host=localhost;Database=Test;" />
      </connectionStrings>
      <system.web>
        ...
        <profile defaultProvider="AspNetMySqlProfileProvider" >
          <providers>
            <add
              name="AspNetMySqlProfileProvider"
              type="Devart.Data.MySql.Web.Providers.MySqlProfileProvider,
                    Devart.Data.MySql.Web, Version=8.3.215.0, Culture=neutral, 
                    PublicKeyToken=09af7300eec23701"
              connectionStringName="MySqlServices" />
          </providers>
          <properties>
            <add name="ZipCode" />
            <add name="CityAndState" />
          </properties>
        </profile>
      </system.web>
    </configuration>
    

    Note: replace "8.3.215.0" with the actual provider version.

    Here ZipCode and CityAndState are examples of profile elements. For detailed information on how to construct properties section refer to MSDN.

    Session State provider

    The session-state store provider is called by the SessionStateModule class during the processing of an ASP.NET page to communicate with the data store for the storage and retrieval of session variables and related session information such as the time-out value. Session data within each ASP.NET application is stored separately for each SessionID property. ASP.NET applications do not share session data.

    For information on how to employ this functionality refer to ASP.NET Session State topic in MSDN. The following example shows the Web.config file for an ASP.NET application configured to use MySqlSessionStateStore.

    <configuration>
      <appSettings/>
      <connectionStrings>
        <add name="MySqlServices"
             connectionString="User Id=root;Host=localhost;Database=Test;"/>
      </connectionStrings>
      <system.web>
        <sessionState
          cookieless="true"
          regenerateExpiredSessionId="true"
          mode="Custom"
          customProvider="MySqlSessionProvider">
          <providers>
            <add name="MySqlSessionProvider"
              type="Devart.Data.MySql.Web.Providers.MySqlSessionStateStore,
                    Devart.Data.MySql.Web, Version=8.3.215.0, Culture=neutral, 
                    PublicKeyToken=09af7300eec23701"
              connectionStringName="MySqlServices"
              enableExpiredSessionAutoDeletion="true" 
              expiredSessionAutoDeletionInterval="1800"
              writeExceptionsToEventLog="false"/>
          </providers>
        </sessionState>
      </system.web>
    </configuration>
    

    Note: replace "8.3.215.0" with the actual provider version.

    The sessions, created by ASP.NET have a timeout value for each session (by default, 20 minutes). If a session is not accessed within the timeout interval, it is considered expired, and is no longer valid. The date and time when the session expires is stored in the Expires column of the aspnet_sessions table.

    By default, expired sessions are not deleted from the table automatically. You can use the enableExpiredSessionAutoDeletion parameter to enable automatic deletion of the expired sessions and the expiredSessionAutoDeletionInterval to specify the interval between automatic deletions of expired sessions, as shown in the example above.

    Site Map provider

    Site Map provider provides the interface between ASP.NET's data-driven site-navigation features and site map data sources. The fundamental job of MySqlSiteMapProvider is to read site map data from a data source and build an upside-down tree of SiteMapNode objects, and to provide methods for retrieving nodes from the site map. Each node in the tree represents one node in the site map. Node properties such as Title, Url, and ChildNodes define the characteristics of each node and allow the tree to be navigated in any direction.

    To access this functionality use Devart.Data.MySql.Web.Providers.MySqlSiteMapProvider class. It behaves as described in reference for System.Web.SiteMaProvider class. The following example shows the Web.config file for an ASP.NET application configured to use MySqlSiteMaProvider.

    <system.web>
      <siteMap defaultProvider="MySqlSiteMapProvider">
        <providers>
          <add name="MySqlSiteMapProvider"
               type="Devart.Data.MySql.Web.Providers.MySqlSiteMapProvider,
                     Devart.Data.MySql.Web, Version=8.3.215.0, Culture=neutral,
                     PublicKeyToken=09AF7300EEC23701"
               connectionStringName="ConnectionString"
               securityTrimmingEnabled="true"
               />
        </providers>
      </siteMap>
    </system.web>
    

    Note: replace "8.3.215.0" with the actual provider version.

    Web Event provider

    Web Event provider provides the interface between ASP.NET's health monitoring subsystem and data sources that log or further process the events ("Web events") fired by that subsystem.

    To access this functionality use Devart.Data.MySql.Web.Providers.MySqlWebEventProvider class. It behaves as described in reference for System.Web.Management.WebEventProvider class. The following example shows the Web.config file for an ASP.NET application configured to use MySqlWebEventProvider. Note that proper use of the provider also requires many other subsections of healthMonitoring to be correctly configured.

    <system.web>
      <healthMonitoring enabled="true" heartbeatInterval="0">
        ...
        <providers>
          <clear/>
          <add name="MySqlWebEventProvider"
               type="Devart.Data.MySql.Web.Providers.MySqlWebEventProvider,
                     Devart.Data.MySql.Web, Version=8.3.215.0, Culture=neutral,
                     PublicKeyToken=09AF7300EEC23701"
               connectionStringName="ConnectionString"
               maxEventDetailsLength="1073741823"
               buffer="false"
               bufferMode="Notification" />
        </providers>
        ...
      </healthMonitoring>
    <system.web>
    

    Note: replace "8.3.215.0" with the actual provider version.

    Personalization provider

    The fundamental job of a personalization provider is to provide persistent storage for personalization state regarding the content and layout of web pages.

    To access this functionality use Devart.Data.MySql.Web.Providers.MySqlPersonalizationProvider class. It behaves as described in reference for System.Web.UI.WebControls.WebParts.PersonalizationProvider class. The following example shows the Web.config file for an ASP.NET application configured to use MySqlPersonalizationProvider.

    <system.web>
        <webParts>
          <personalization defaultProvider="WebPartProvider">
            <providers >
              <add name="WebPartProvider"
                   connectionStringName="ConnectionString"
                   type="Devart.Data.MySql.Web.Providers.MySqlPersonalizationProvider,
                         Devart.Data.MySql.Web, 8.3.215.0, Culture=neutral,
                         PublicKeyToken=09af7300eec23701" />
            </providers>
          </personalization>
        </webParts>
    <system.web>
    

    Note: replace "8.3.215.0" with the actual provider version.

    Deployment

    To deploy ASP.NET applications written with dotConnect for MySQL you should register run-time assemblies Devart.Data.dll, Devart.Data.MySql.dll, and Devart.Data.MySql.Web.dll at Global Assembly Cache (GAC) for appropriate framework or place it in the folder of your application (Bin folder for web projects).

    Also place App_Licenses.dll assembly in the Bin folder. For more information about this assembly refer to Licensing topic.

    Keep in mind that web application are usually run in a partially trusted environment. Here are the permissions required by dotConnect for MySQL: