c# - 具有 MVC 2.0 Web 配置的自定义角色提供程序

标签 c# asp.net asp.net-mvc web-config

我有一个自定义的 MembershipProvider 和一个自定义的 RoleProvider。我通过创建一个实现 MembershipProvider 类的 SimpleMembershipProvider 类来创建自定义 MembershipProvider。之后我更改了我的 web.config 并开始工作。

所以我使用相同的方法创建了一个自定义 RoleProvider。没什么特别的,只是创建一个实现 RoleProvider 类的 SimpleRoleProvider 类。但是当我更改 web.config 文件并运行解决方案时,我收到以下错误消息:

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" />

所以我在网上搜索了一下。并尝试了 type 属性,它会产生以下错误:

 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" />

关于如何让这个 CustomRoleProvider 工作的任何建议? 非常感谢任何帮助!

最佳答案

从您获得的第一个异常开始,DashboardRoleProvider 需要有一个无参数的构造函数。否则框架无法实例化您的角色提供者。

在第二个示例中,您可能希望使用完全限定的程序集名称。

迈克尔

关于c# - 具有 MVC 2.0 Web 配置的自定义角色提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2427718/

相关文章:

c# - 如何用列表初始化类?

C# - 更改任务栏的图标

c# - SQL session 状态 : some fields become null

jquery - 如何检查ajax调用中的 session 是否过期?

asp.net-mvc - 更新身份 1 到 2 后,没有 IUserTokenProvider 已注册错误

c# - 如何识别 URL 的身份验证类型?

c# - 从 DataGridView 中删除行时出现意外行为

asp.net - 您的下一个 ASP.NET 项目的选择是什么 : Web Forms or MVC?

asp.net-mvc - 添加迁移 : Value does not fall within expected range

asp.net-mvc - "The Id field is required"创建时的验证消息; ID 未设置为 [必填]