自定义角色提供程序Web配置错误

时间:2011-09-12 13:09:46

标签: c# silverlight roleprovider

我为Silverlight应用程序编写了自定义roleProvider。 不幸的是我在加载时遇到错误:

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: Exception has been thrown by the target of an invocation.

Source Error:

Line 46:       <providers>
Line 47:         <clear />
Line 48:         <add name="LanosRoleProvider" type="LANOS.Web.Security.LanosRoleProvider" applicationName="/" />
Line 49:       </providers>
Line 50:     </roleManager>


Source File: C:\path\LANOS\LANOS.Web\web.config    Line: 48 

这是我的角色提供者的定义(类在Lanos.Web项目中):

namespace LANOS.Web.Security
{
    public class LanosRoleProvider : RoleProvider

我真的不知道为什么这不起作用。在将它添加到我的应用程序之前,我已经在一些示例项目上测试了它并且工作正常。有任何想法吗?

或者至少你能告诉我如何显示配置加载时抛出的异常信息吗?

3 个答案:

答案 0 :(得分:2)

您运行的是哪个版本的ASP.NET?

如果您的程序集是LANOS.Web.Security:

,我建议将程序集添加到元素中
<add name="LanosRoleProvider" type="LANOS.Web.Security.LanosRoleProvider, LANOS.Web.Security" applicationName="/" connectionStringName="abcConnectionString" />

<强>已更新

connectionStringName是必需属性,这就是消息是解析错误的原因。这也意味着您必须在部分中定义连接字符串。

<connectionStrings>
   <add name="abcConnectionString" connectionString="blah" />
 </connectionStrings>

希望这有帮助。

答案 1 :(得分:1)

刚遇到这个问题,我的问题是我正在使用属性注入来处理Custom Roles Provider使用的服务。此服务还要求构造函数注入其依赖项。我错过了这些构造函数依赖项之一的绑定,这导致抛出这种模糊错误。我尝试在here上解释这个问题。

我希望它可以帮助像谷歌一样来谷歌的人。

答案 2 :(得分:0)

这发生在我身上,因为我的RoleProvider的构造函数中抛出了异常。 检查构造函数调用链和私有成员默认分配。

我的特殊问题是由构造函数中的EntityFramework问题引起的。

清除提供程序中的所有构造函数代码并进行测试以查看错误是否消失,并且您将知道自己处于正确的轨道上。

相关问题