【问题标题】:How to inherits a class located in the App_Code folder from a web.config section? What would be the namespace?如何从 web.config 部分继承位于 App_Code 文件夹中的类?命名空间是什么?
【发布时间】:2016-07-24 14:32:39
【问题描述】:

我创建了一个类并放置在 App_Code 文件夹中。当我尝试从 Web.config 文件访问时,我得到一个异常:找不到配置文件默认提供程序

<profile defaultProvider="SqlProvider" inherits="CustomUserProfile">
    <providers>
      <clear />
      <add name="ProfileProvider"
       connectionStringName="LocalSqlServer"
       type="System.Web.Profile.SqlProfileProvider, 
       System.Web, Version=4.0.0.0, 
       Culture=neutral, 
       PublicKeyToken=b03f5f7f11d50a3a"
       description="SqlProfileProvider extra fields"
       applicationName="/" />
    </providers>
  </profile>

当我添加这段代码时:

<profile defaultProvider="SqlProvider" inherits="MyApp.App_Code.CustomUserProfile">

我遇到了另一个错误。

Compiler Error Message: BC30002: Type 'MyApp.App_Code.CustomUserProfile' is not defined.

我想知道位于 App_Code 文件夹中的文件的命名空间是什么?

感谢您的帮助。

【问题讨论】:

  • 试试 MyApp.CustomUserProfile
  • 删除App_Code 让我回到之前的错误,即:The profile default provider was not found.
  • 为什么不在你的类周围添加一个命名空间,以便你明确知道它是什么?
  • 在显式命名空间中包装类并不能解决问题。我仍然遇到同样的错误:The profile default provider was not found.
  • unable to call App_Code class from a code-behind 是否与您的问题有关?

标签: asp.net


【解决方案1】:

DefaultProvider 应该与提供者中添加的名称匹配,如下所示:

<profile defaultProvider="ProfileProvider" inherits="CustomUserProfile">

【讨论】:

  • 我有两个做了两个更改。 1)按照其他地方的建议,将构建操作更改为编译 2)将项目名称添加到类名称之前,例如inherits="MyApp.CustomUserProfile"。除此之外,最大的问题是您指出的,即我只是复制/粘贴而没有注意内容。默认提供程序名称应与我添加的提供程序相同。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2014-05-05
  • 1970-01-01
  • 2017-12-10
  • 1970-01-01
  • 1970-01-01
  • 2020-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多