RoleProvider .NET 2 - 从 MS Access 转换为 MySQL

RoleProvider .NET 2 - converted from MS Access to MySQL

我在 .NET 2 上有一个旧站点 运行 使用 AccessMembershipProvide,我正在将其更改为 MySqlMemebrshipProvider - 成员身份方面工作正常,但角色部分似乎不提供角色方法?

如果我切换回 Web.Config 中的 OdbcRoleProvide,它仍然可以使用 MySqlMembershipProvider。

我正在调用角色:Response.Write(Roles.IsUserInRole(User.Identity.Name, "Admin") & " -role exist- " & Roles.RoleExists("Admin"))

这 returns false 即使用户已登录。?

注意:我 运行 它在托管站点上,无法访问 Visual Studio(我知道这会使调试变得异常困难)!!!

Web.Config:

  <connectionStrings>
<clear />
<add name="OdbcServices" connectionString="Driver={Microsoft Access Driver (*.mdb)};Dbq=e:\App_Data\subsite.mdb;" />
<add name="ConnString" connectionString="Database=Training;Data Source=localhost;User Id=myuser;Password=mypassword" />
</connectionStrings>
<system.web>

<compilation debug="true" strict="false" explicit="true">
    <codeSubDirectories>
        <add directoryName="VBCode" />
        <add directoryName="CSCode" />
    </codeSubDirectories>
</compilation>
<!--
<membership defaultProvider="AccessMembershipProvider"
            userIsOnlineTimeWindow="20">
  <providers>
    <clear />
    <add name="AccessMembershipProvider"
 type="AccessMembershipProvider"
 enablePasswordReset="true"
 enablePasswordRetrieval="true"
 requiresQuestionAndAnswer="true"
 connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\App_Data\subsite.mdb;Persist Security Info=False"
 />
  </providers>

</membership>

<roleManager defaultProvider="OdbcRoleProvider"
    enabled="true"
    cacheRolesInCookie="true"
    cookieName=".ASPROLES"
    cookieTimeout="30"
    cookiePath="/"
    cookieRequireSSL="false"
    cookieSlidingExpiration="true"
    cookieProtection="All" >

  <providers>
    <clear />
    <add name="OdbcRoleProvider"
      type="Samples.AspNet.Roles.OdbcRoleProvider"
      connectionStringName="OdbcServices"
      applicationName="SampleApplication"
      writeExceptionsToEventLog="false" />

  </providers>

</roleManager>
-->

<!-- http://www.codeproject.com/Articles/12301/Membership-and-Role-providers-for-MySQL -->

<roleManager defaultProvider="MySqlRoleProvider"
    enabled="true"
    cacheRolesInCookie="true"
    cookieName=".ASPROLES"
    cookieTimeout="30"
    cookiePath="/"
    cookieRequireSSL="false"
    cookieSlidingExpiration="true"
    cookieProtection="All" >
<providers>
    <clear />
    <add
        name="MySqlRoleProvider"
        type="Andri.Web.MySqlRoleProvider"
        connectionStringName="ConnString"
        applicationName="SampleApplication"
        writeExceptionsToEventLog="false"
    />
</providers>
</roleManager>

<membership defaultProvider="MySqlMembershipProvider" 
            userIsOnlineTimeWindow="15">
    <providers>
        <clear />
        <add
            name="MySqlMembershipProvider"
            type="Andri.Web.MySqlMembershipProvider"
            connectionStringName="ConnString"
            applicationName="ApplicationName"
            enablePasswordRetrieval="true"
            enablePasswordReset="true"
            requiresQuestionAndAnswer="true"
            requiresUniqueEmail="false"
            passwordFormat="Clear"
            writeExceptionsToEventLog="false"
        />
  </providers>
</membership>


<authentication mode="Forms">
  <forms loginUrl="~/Login.aspx" />
</authentication>

...

不确定为什么恢复到 RolesProvider.vb 没有引起相同的响应,但是 MembershipProvider.cs 中有一个错误的 SQL 语句。这解决了问题并且 RolesProvider 正在根据需要做出响应。