【问题标题】:Custom role provider web config error自定义角色提供程序 Web 配置错误
【发布时间】:2011-09-12 13:09:45
【问题描述】:

我已经为我的 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

我真的不知道为什么这不起作用。在将它添加到我的应用程序之前,我已经在一些示例项目中对其进行了测试,并且效果很好。有任何想法吗?

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

【问题讨论】:

    标签: c# silverlight roleprovider


    【解决方案1】:

    您运行的是什么版本的 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>
    

    希望这会有所帮助。

    【讨论】:

    • 您好,感谢您的回答。类文件在项目内部,不在外部 dll 中。项目的程序集名称是 LANOS.Web。不幸的是,添加程序集名称并没有解决问题。 ASP 的版本是:4.0.30319.225 也许有什么提示我可以记录这个异常吗?
    • @neurotix 查看更新。另请参阅 msdn.microsoft.com/en-us/library/ms164655.aspx 如果这仍然没有帮助,可能会为您提供更多信息。
    【解决方案2】:

    刚刚遇到这个问题,我的问题是我正在为自定义角色提供程序使用的服务使用属性注入。该服务还要求其依赖项由构造函数注入。我错过了这些构造函数依赖项之一的绑定,导致抛出这个模棱两可的错误。我尝试在here 上解释这一点。

    我希望它能像我一样帮助来自谷歌的人。

    【讨论】:

    • 您的博客链接转到 404。您有更新的链接吗?
    • @berniefitz 已更新。
    【解决方案3】:

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

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

    清除提供程序中的所有构造函数代码并测试以查看错误是否消失,您就会知道您走在正确的轨道上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 2014-02-03
      • 1970-01-01
      相关资源
      最近更新 更多