RoleProvider .NET 2 - converted from MS Access to MySQL

家住魔仙堡 提交于 2019-12-12 02:39:32

问题


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?

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

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

this returns false even with logged in user.?

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:

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

...

回答1:


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.



来源:https://stackoverflow.com/questions/39191498/roleprovider-net-2-converted-from-ms-access-to-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!