本文介绍了RoleProvider .NET 2-从MS Access转换为MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用AccessMembershipProvide在.NET 2上运行的旧站点,并且将其更改为MySqlMemebrshipProvider-成员身份方面还不错,但是角色部分似乎未提供角色方法?

I have an old site running on .NET 2 using an AccessMembershipProvide and I'm changing it to MySqlMemebrshipProvider - The membership side works fine, but the roles part seems to not provide the roles methods?

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

If I switch back to the OdbcRoleProvide in the Web.Config it works while still using the MySqlMembershipProvider.

我用以下角色称呼这些角色:Response.Write(Roles.IsUserInRole(User.Identity.Name, "Admin") & " -role exist- " & Roles.RoleExists("Admin"))

I'm calling the roles with: Response.Write(Roles.IsUserInRole(User.Identity.Name, "Admin") & " -role exist- " & Roles.RoleExists("Admin"))

即使已登录的用户也返回false.

this returns false even with logged in user.?

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

NOTE: I'm running it on a hosted site and don't have access to Visual Studio (I know this makes debugging incredibly difficult)!!!

Web.Config:

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可以根据需要进行响应.

Not sure why reverting back to RolesProvider.vb did not cause the same response, however there was an erroneous SQL statement in the MembershipProvider.cs. This resolved the problem and the RolesProvider is responding as desired.

这篇关于RoleProvider .NET 2-从MS Access转换为MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:41