mardi 22 décembre 2015

Attempting to create a custom membership provider with SQLite MVC 5

This is my first time working with a membership provider (I usually just let Identity do it's magic).

Basically I am working with a SQLite database and after searching the best way would just to create my own Membership Provider.

The problem is when the below method gets called an exception is thrown:

public override MembershipUser GetUser(string username, bool userIsOnline)
{
    var user = Repo.GetUserByUserName(username);
    if (user != null)
    {
        var memUser = new MembershipUser( <-- Exception here
            "CustomMembershipProvider",
            username,
            user.UserID,
            user.UserEmailAddress,
            string.Empty,
            string.Empty,
            true,
            false,
            DateTime.MinValue,
            DateTime.MinValue,
            DateTime.MinValue,
            DateTime.Now,
            DateTime.Now);
        return memUser;
    }
    return null;
}

Exception

The membership provider name specified is invalid. Parameter name: providerName

Exception Details: System.ArgumentException: The membership provider name specified is invalid. Parameter name: providerName

I have read this is to do with my web.config:

// Section handler
<section name="membership" type="NZBDash.Core.CustomMembershipProvider, NZBDash.Core, Version=1.0.0.0, Culture=neutral" />

<membership defaultProvider="CustomMembershipProvider">
    <providers>
      <clear/>
      <add name="CustomMembershipProvider"
          type="NZBDash.Core.CustomMembershipProvider"
          connectionStringName="AppDb"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="false"
          requiresUniqueEmail="false"
          maxInvalidPasswordAttempts="5"
          minRequiredPasswordLength="6"
          minRequiredNonalphanumericCharacters="0"
          passwordAttemptWindow="10"
          applicationName="Database" />
    </providers>
  </membership>

Anyone have any idea what I am doing wrong here?

Aucun commentaire:

Enregistrer un commentaire