自定义 RoleProvider 和 无法加载类型

3

我有自定义的会员和角色提供程序,在调试时出现以下错误:

解析器错误消息:无法加载类型“Classiffieds.WebProviders.ClassiffiedsRoleProvider”。

源错误:

 <add applicationName="/" 
      name="ClassiffiedsRoleProvider" 
      type="Classiffieds.WebProviders.ClassiffiedsRoleProvider" />

Web.config配置文件如下所示

<roleManager enabled="true" defaultProvider="ClassiffiedsRoleProvider">
   <providers>
      <clear />
      <add applicationName="/" 
            name="ClassiffiedsRoleProvider" 
            type="Classiffieds.WebProviders.ClassiffiedsRoleProvider" />
      </providers>
</roleManager>

ClassifiedsRoleProvider.cs

namespace Classiffieds.WebProviders
{
    public sealed class ClassiffiedsRoleProvider: RoleProvider
    ...
}

我在这里做错了什么?

谢谢

更新: 定制角色提供程序位于分离的项目Classiffieds.WebProviders中。

ClassName: ClassiffiedsRoleProvider

and

AssemblyName: Classiffieds.WebProviders

根据建议,我尝试了以下操作:

<add applicationName="/" 
    name="ClassiffiedsRoleProvider" 
    type="Classiffieds.WebProviders.ClassiffiedsRoleProvider,Classiffieds.WebProviders" />

但错误信息仍然存在 解析器错误消息:无法加载文件或程序集 'Classiffieds.WebProviders' 或其某个依赖项。系统找不到指定的文件。


你的Web应用程序项目中是否有对具有自定义角色提供程序的项目(或dll的引用)的引用? - Hanno
2个回答

9
很可能您的提供程序在另一个程序集中。请提供完整名称。
type="Classiffieds.WebProviders.ClassiffiedsRoleProvider, name.of.your.assembly.without.dll"

也许我错了,但我认为我已经在type="Classiffieds.WebProviders.ClassiffiedsRoleProvider" />中设置了完整的程序集名称。 - user1765862
1
不行,我只能看到命名空间.类型名。你漏了逗号和程序集名称(", Classifieds.WebProvider" 或者其他程序集的名称)。 - Wiktor Zychla
抱歉,我现在看到了,问题已经更新了,但我的问题仍然存在。 - user1765862
1
如果在Application_Start中执行Type type=Type.GetType("Classiffieds.WebProviders.ClassiffiedsRoleProvider, Classiffieds.WebProviders")(首先从web.config中删除提供程序),会出现什么情况?异常和内部异常会显示什么? - Wiktor Zychla
我在web.config中注释掉了roleManager,并在app.start中的...GetType代码处添加了断点。在调试时,类型变量为空。 - user1765862
显示剩余4条评论

2
如果您的角色提供程序类在App_Code文件夹中,那么您需要将该类文件的“Build Action”属性更改为“编译”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接