dotConnect Universal Documentation
In This Topic
    ASP.NET Provider Model Support
    In This Topic

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

    In dotConnect Universal you can use the ASP.NET 2.0 provider model with data providers for Oracle, MySQL, PostgreSQL, and SQL Server.

    dotConnect Universal implements Membership provider, Role provider, Session State provider and Profile provider. This article provides information on how to set up ASP.NET application to use dotConnect Universal as one of these providers. It consists of following sections:

    Installation and setup

    All providers are contained in Devart.Data.Universal.Web.dll assembly. You have to add reference to this assembly in your project in order to use 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 script InstallWebTables.sql against database you wish to use. The script can be found in the installation pack for actual data provider.

    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 a 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 Devart.Data.Universal.Web.Providers.UniMembershipProvider class. It behaves as described in reference for System.Web.Security.MembershipProvider class. The following example shows the Web.config file for an ASP.NET application configured to use UniMembershipProvider.

    <configuration>
      <connectionStrings>
          <add name="UniServices" connectionString="Provider=MySQL;User Id=root;Host=localhost;Database=Test" providerName="Devart.Data.Universal"/>
      </connectionStrings>
      <system.web>
        ...
        <membership defaultProvider="AspNetUniMembershipProvider"
          userIsOnlineTimeWindow="15">
          <providers>
            <add 
              name="AspNetUniMembershipProvider" 
              type="Devart.Data.Universal.Web.Providers.UniMembershipProvider,
                    Devart.Data.Universal.Web, Version=3.50.790.0, Culture=neutral,
                    PublicKeyToken=09af7300eec23701" 
              connectionStringName="UniServices"
              enablePasswordRetrieval="false"
              enablePasswordReset="true"
              requiresQuestionAndAnswer="true"
              requiresUniqueEmail="false"
              passwordFormat="Hashed"
              maxInvalidPasswordAttempts="5"
              passwordAttemptWindow="10" />
          </providers>
        </membership>
      </system.web>
    </configuration>
    

    Note: replace "3.50.790.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 whether what role or roles the user belongs to. The role manager also implements admninistrative methods such as Roles.CreateRole and Roles.AddUserToRole by calling the underlying methods in the provider.

    To access this functionality use Devart.Data.Universal.Web.Providers.UniRoleProvider class. It behaves as described in reference for System.Web.Security.RoleProvider class. The following example shows the Web.config file for an ASP.NET application configured to use UniRoleProvider. Note that you can configure the UniRoleProvider to use the same database and user information as the UniMembershipProvider in order to use a single database for authentication and authorization information.

    <configuration>
      <connectionStrings>
          <add name="UniServices" connectionString="Provider=MySQL;User Id=root;Host=localhost;Database=Test" providerName="Devart.Data.Universal"/>
      </connectionStrings>
      <system.web>
        ...
        <membership defaultProvider="AspNetUniMembershipProvider"
          userIsOnlineTimeWindow="15">
          <providers>
            <add 
              name="AspNetUniMembershipProvider" 
              type="Devart.Data.Universal.Web.Providers.UniMembershipProvider,
                    Devart.Data.Universal.Web, Version=3.50.790.0, Culture=neutral,
                    PublicKeyToken=09af7300eec23701" 
              connectionStringName="UniServices"
              enablePasswordRetrieval="false"
              enablePasswordReset="true"
              requiresQuestionAndAnswer="true"
              requiresUniqueEmail="false"
              passwordFormat="Hashed"
              maxInvalidPasswordAttempts="5"
              passwordAttemptWindow="10" />
          </providers>
        </membership>
        <roleManager defaultProvider="AspNetUniRoleProvider" 
          enabled="true"
          cacheRolesInCookie="true"
          cookieName=".ASPROLES"
          cookieTimeout="30"
          cookiePath="/"
          cookieProtection="All" >
          <providers>
            <add
              name="AspNetUniRoleProvider"
              type="Devart.Data.Universal.Web.Providers.UniRoleProvider"
              connectionStringName="UniServices" />
          </providers>
        </roleManager>
      </system.web>
    </configuration>
    

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

    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 UniSessionStateStore.

    <configuration>
      <appSettings/>
      <connectionStrings>
          <add name="UniServices" connectionString="Provider=MySQL;User Id=root;Host=localhost;Database=Test" providerName="Devart.Data.Universal"/>
      </connectionStrings>
      <system.web>
        <sessionState 
          cookieless="true" 
          regenerateExpiredSessionId="true" 
          mode="Custom" 
          customProvider="UniSessionProvider">
          <providers>
            <add name="UniSessionProvider" 
              type="Devart.Data.Universal.Web.Providers.UniSessionStateStore,
                    Devart.Data.Universal.Web, Version=3.50.790.0, Culture=neutral,
                    PublicKeyToken=09af7300eec23701" 
              connectionStringName="UniSessionServices" 
              enableExpiredSessionAutoDeletion="true" 
              expiredSessionAutoDeletionInterval="1800"
              writeExceptionsToEventLog="false"/>
          </providers>
        </sessionState>
      </system.web>
    </configuration>
    

    Note: replace "3.50.790.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.

    Note that .NET Framework Data Provider for SQL Server requires connection string as additional attribute of tag sessionState:

    sqlConnectionString="Server=SqlServer;Initial catalog=ASPState;User Id=sa;"

    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 UniProfileProvider.

    <configuration>
      <connectionStrings>
          <add name="UniServices" connectionString="Provider=MySQL;User Id=root;Host=localhost;Database=Test" providerName="Devart.Data.Universal"/>
      </connectionStrings>
      <system.web>
        ...
        <membership defaultProvider="AspNetUniMembershipProvider"
          userIsOnlineTimeWindow="15">
          <providers>
            <add 
              name="AspNetUniMembershipProvider" 
              type="Devart.Data.Universal.Web.Providers.UniMembershipProvider" 
              connectionStringName="UniServices"
              enablePasswordRetrieval="false"
              enablePasswordReset="true"
              requiresQuestionAndAnswer="true"
              requiresUniqueEmail="false"
              passwordFormat="Hashed"
              maxInvalidPasswordAttempts="5"
              passwordAttemptWindow="10" />
          </providers>
        </membership>
        <profile defaultProvider="AspNetUniProfileProvider" >
          <providers>
            <add
              name="AspNetUniProfileProvider"
              type="Devart.Data.Universal.Web.Providers.UniProfileProvider"
              connectionStringName="UniServices" />
          </providers>
          <properties>
            <add name="ZipCode" />
            <add name="CityAndState" />
          </properties>
        </profile>
      </system.web>
    </configuration>
    

    Note: replace "3.50.790.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.