gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:11:29 25 4
gpt4 key购买 nike

我有一个自定义的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com