Custom Role Package with MVC 2.0 webconfig

I have a custom MemberhipProvider and a custom RoleProvider. I created a custom MemberhipProvider by creating a SimpleMembershipProvider class that implements the MembershipProvider class. After that I changed my web.config and it worked.

So, I used the same approach, creating a custom RoleProvider. Nothing special, just creating a SimpleRoleProvider class that implements the RoleProvider class. But then, when I change the web.config file and run the solution, I get the following error message:

Web.config

<membership defaultProvider="DashboardMembershipProvider"> <providers> <clear/> <add name="SimpleMembershipProvider" type="Dashboard.Web.Controlling.Account.SimpleMembershipProvider" /> </providers> </membership> <roleManager enabled="true" defaultProvider="DashboardRoleProvider"> <providers> <clear/> <add name="DashboardRoleProvider" type="Dashboard.Web.Controlling.Account.DashboardRoleProvider" /> </providers> </roleManager> Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: No parameterless constructor defined for this object. Source Error Line 78: <add name="SimpleRoleProvider" Line 79: type="Dashboard.Web.Controlling.Account.SimpleRoleProvider" /> 

So, I searched on the Internet. And I tried the type attribute, which generates the following errors:

  Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Could not load file or assembly 'Dashboard.Web.Controlling.Account' or one of its dependencies. The system cannot find the file specified. Source Error: Line 78: <add name="SimpleRoleProvider" Line 79: type="Dashboard.Web.Controlling.Account.SimpleRoleProvider,Dashboard.Web.Controlling.Account" /> 

Any suggestions on how I can get this CustomRoleProvider to work? Any help is much appreciated!

+4
source share
2 answers

As with the first exception you received, the DashboardRoleProvider must have a constructor without parameters. Otherwise, the infrastructure cannot create an instance of the video provider.

In the second example, you can use the fully qualified assembly name instead.

Michael

+3
source
 <add name="SimpleRoleProvider" type="Dashboard.Web.Controlling.Account.SimpleRoleProvider,Dashboard.Web.Controlling.Account" /> 

The type after the first comma is the name of the Assembly, are you sure that the name of your assembly is not just Dashboard.Web?

Right-click on the project and select the properties that will find your assembly name.

+2
source

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


All Articles