IsInRole is always false

Discussion in 'ASP.NET 2.0' started by robertogonzalez, Feb 2, 2010.

  1. I've looked at all the threads posted on this forum and tons more on google searches. However, I can't seem to resolve my issue. I am using the aspnet membership provider and have installed it on the discount sql server without issues. I've been able to login using forms just fine. However, I now need to have some roles. In my code, when I try IsInRole on my own computer but using the same connection strings, providers, rolemanager, and membership settings as in production it recognizes that my user is an admin. However, when I publish the code to the discount server it always returns false. I've looked at all the pertinent tables and there are correct records on all of them. I've executed the stored procedure aspnet_UsersInRoles_IsUserInRole to mimmick the call from the API and it returns 1 which is correct. It seems as though the web app must be using some other RoleProvider for some reason. I've looked and followed this suggestion but to no avail http://community.discountasp.net/showthread.php?t=7860.

    Here's my config:
    <authentication mode="Forms">
    <forms loginUrl="Login.aspx" requireSSL="false" defaultUrl="~/Portal/Default.aspx" timeout="20" cookieless="UseCookies"/>
    </authentication>
    <membership defaultProvider="AspNetSqlMembershipProvider">
    <providers>
    <clear/>
    <add type="System.Web.Security.SqlMembershipProvider" name="AspNetSqlMembershipProvider" connectionStringName="MyiesSecurityConnectionString" applicationName="/Myies" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="3" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="^.*(?=.{7,}).*$"/>
    <add type="System.Web.Security.SqlMembershipProvider" name="AspNetSqlMembershipProviderPasswordReset" connectionStringName="MyiesSecurityConnectionString" applicationName="/Myies" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="3" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="^.*(?=.{7,}).*$"/>
    </providers>
    </membership>
    <roleManager defaultProvider="AspNetSqlMembershipProvider" enabled="true">
    <providers>
    <clear/>
    <add type="System.Web.Security.SqlRoleProvider" name="AspNetSqlMembershipProvider" connectionStringName="MyiesSecurityConnectionString"/>
    </providers>
    </roleManager>


    I've also tried printing out the providers available to the app and they are all valid:
    foreach (MembershipProvider mp in Membership.Providers)
    {
    Response.Write("<br>" + mp.Name + ":" + mp.ApplicationName);
    }

    I'm stuck as I need to deliver admin functionality ASAP.

    I would really appreciate your help.

    Thanks
     
  2. Fixed

    I found the solution to my problem. It's not enough to have the membership provider include an entry for applicationName. The role manager must also have the same entry otherwise the two will not coincide. So, my entry of

    <roleManager defaultProvider="AspNetSqlMembershipProvider" enabled="true">

    should be

    <roleManager defaultProvider="AspNetSqlMembershipProvider" applicationName="/Myies" enabled="true">

    Hope that helps anyone else.
     
  3. mjp

    mjp

    Thanks for posting the follow-up!
     

Share This Page