The method or operation is not implemented in CustomRoleProvider - asp.net-mvc

I am implementing custom role provider for my website.In my web.config file i have add the following code.
web.config
<roleManager enabled="true" defaultProvider="MyRoleProvider">
<providers>
<clear/>
<add name="MyRoleProvider" type="MvcMembership.Models.CustomRoleProvider" applicationName="MvcMembership"/>
</providers>
</roleManager>
I have overdie the createRole method and also initialized the database in initialize method but it is giving error at this line

Related

Authentication on one site using the ASP.NET membership of another

We have one site that uses ASP.NET Membership for its user accounts. Let's say this site is at www.domain.com.
We have another site, let's say at www.domain.com/site2, which already connects to the database of site #1 for other reasons. We'd like to implement a username/password login to site #2, and would like to use the existing login credentials for site #1, as site #1 is where they apply for permission to access various systems, etc.
I'm not trying to create a SSO kind of solution, where signing into one site signs you in to the other, which is what other questions have been about.
I would like them to be able to enter their username and password that they have on site #1, enter it on site #2 and it auths them to site #2.
Is this possible?
Web.config of site #1:
<machineKey decryptionKey="AutoGenerate" validation="SHA1" validationKey="AutoGenerate" />
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="VTDB"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="VTDB"
applicationName="/" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="VTDB"
name="AspNetSqlRoleProvider"
applicationName="/"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
....
Web.config of site #2:
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="VTConnString" />
</providers>
</membership>
<machineKey decryptionKey="AutoGenerate" validation="SHA1" validationKey="AutoGenerate" />
Where VTConnString points to site #1's database.
But when I call Membership.ValidateUser(userName, password) in site #2, it always returns false.
I figured out the issue:
I was missing applicationName="/" in site #2's web.config. Now that the applicationNames are set the same, it works correctly.

Users don't load Sitefinity

I'm having an issue with SitefinityMembershipProvider in Sitefinity 9.1
When I login to the backend, navigate to Administration -> Users:Page keeps loading.
When I checked the error log it tells me that "Provider must implement the class 'System.Web.Security.MembershipProvider".
But my class inherits sitefinity membership provider i.e. MembershipDataProvider
which is of type Telerik.Sitefinity.Security.Data.
My web config have the following membership defined.
<membership defaultProvider="Default">
<providers>
<clear />
<add name="Default" type="Telerik.Sitefinity.Security.Data.SitefinityMembershipProvider, Telerik.Sitefinity" />
<add name="CredentialServiceProvider" type="SitefinityWebApp.Providers.CredentialServiceProvider" />
</providers>
You need to register the provider in the Security settings as explained here:
http://docs.sitefinity.com/custom-membership-provider-add-the-new-provider-to-the-sitefinity-providers-collection
Additionally, I had to remove the custom provider from the web.config
<providers>
<clear />
<add name="Default" type="Telerik.Sitefinity.Security.Data.SitefinityMembershipProvider, Telerik.Sitefinity" />
</providers>

Error Unable connect to SQL Server when add <roleManager enabled="true">

When I add
<roleManager enabled="true"></roleManager>
to my web.config, I get an error
Unable to connect to SQL Server database
occurs on this line of code:
System.Web.Security.Roles.AddUserToRole(m.UserName, "admin");
I added this to the web.config and it solved my problem:
<system.web>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" />
</providers>
</roleManager>
</system.web>
I had the exact same error when I had enabled believing I was enabling ASP.NET Identity 2. They are not the same! The enabled an old version of identity management which uses a different table structure to ASP.NET Identity 2 (which doesn't need "enabling" by the way - it's just there).
check the connection String.
If you are intentionally using the old role-manager and still getting the error you might be looking at the default localdb instead of your database, in which case you can modify to point at any connection string you want:
<roleManager
enabled="true"
cacheRolesInCookie="true"
defaultProvider="OurSqlRoleProvider"
>
<providers>
<add
connectionStringName="DefaultConnection"
applicationName="/"
name="OurSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
If you are are after using ASP.NET Identity 2, here's an article on it:
http://johnatten.com/2014/04/20/asp-net-mvc-and-identity-2-0-understanding-the-basics/

ERROR: Key cannot be null. Parameter name: key

SOLVED:the method public override string[] GetRolesForUser(string username) was erroneously returning null as the first item of the array.All good now.
I am trying to implement custom role and membership providers for my application but not having luck with role provider. In one of my controller's method, if I have [Authorize] directive it works fine but when I want to have role based authorization by adding [Authorize(Roles = "Admin")] it gives an error saying 'Key cannot be null. Parameter name: key' .
I think there is something wrong with the entires in web.config file but cannot find what it is. The modified entries in web.config file look like
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear />
<add name="CustomMembershipProvider" type="eLibrary.Models.CustomMembershipProvider" connectionStringName="AppDb" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="true" >
<providers>
<clear/>
<add name="CustomRoleProvider" type="eLibrary.Models.CustomRoleProvider" />
</providers>
</roleManager>
It would be great if anyone can throw some lights on.
SOLVED:the method public override string[] GetRolesForUser(string username) was erroneously returning null as the first item of the array.All good now.

Explicitly changing a connection string for MembershipProvider

I am using the following provider to look up users from ADAM. I would be able to like to change the connection string dynamically depending on the type of user. How can I achiev this?
<add name="con1" connectionString="LDAP://con1.url" />
<add name="con2" connectionString="LDAP://con2.url" />
<providers>
<add name="ConnectionProvider" connectionStringName="con1" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" attributeMapUsername="userPrincipalName" enableSearchMethods="true" />
</providers>
You can get specific sections of the .config by using the ConfigurationManager.GetSection() method (System.Configuration namespace). From here, just apply the logic and select the connection string you want.

Resources