Custom Role Provider Does Not Implement Inherited Abstract Element

I need help creating a custom role provider in an asp.net mvc application.

The problem is that I get a few errors, such as:

MyRoleProvider does not implement inherited abstract member 'System.Web.Security.RoleProvider.RoleExists(string)

I get the same error for other methods. However, I have implementations for those who ...

My web.config has the following:

<roleManager enabled="true" defaultProvider="MyCustomProvider">
  <providers>
     <add name="MyCustomProvider" type="MyRoleProvider" />
  </providers>
</roleManager>

My custom role provider looks like this (I skipped a few methods):

public class MyRoleProvider : RoleProvider {
        public override string ApplicationName {
                get { throw new NotImplementedException(); }
                set { throw new NotImplementedException(); }
        }
        public override bool RoleExists(string roleName)
        {
                throw new NotImplementedException();
        }
        public override bool IsUserInRole(string username, string roleName)
                return true;
        }
}

What am I doing wrong? (I am not very familiar with this).

+3
source share
2 answers

When you create a custom provider, especially in Visual Studio, Intellisense will populate the contents of the override elements:

throw new NotImplementedException();

, , , , RoleProvider, . Visual studio , , . , , , , .net , .

, throw . , IsUserInRole , ( SQL, XML ..), true, , - false.

+4

NotImplementedException RoleExists. return true;, .

0

Source: https://habr.com/ru/post/1725191/


All Articles