【问题标题】:Is the web.config/app.config element configSections deprecated in DotNet4.5?Web.config/app.config 元素 configSections 在 DotNet4.5 中是否已弃用?
【发布时间】:2018-05-17 19:22:26
【问题描述】:

我在 ASP.Net (3.5) 中有一个需要升级的旧应用程序,但是,在更新到 4.5 后,无法识别 web.config 文件中的 configSections 元素并且应用程序无法加载。这里有什么变化吗?

以下曾经工作...

<configuration>
  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>

  <!-- PayPal SDK settings -->
  <paypal>
    <settings>
      <add name="mode" value="sandbox"/>
      <add name="clientId" value="YOUR APPLICATION CLIENT ID"/>
      <add name="clientSecret" value="YOUR APPLICATION CLIENT SECRET"/>
    </settings>
  </paypal>
</configuration>

但没有快乐

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.


Config Source:
   22:   
   23:   <configSections>
   24:     <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />

【问题讨论】:

  • 我在 4.6.1 中有一个网站,其中包含 configSections 元素。
  • 确保您的应用程序池用户对网站目录具有读取权限。还转到 IIS 管理器,在左窗格中选择您的网站,然后双击右窗格中的处理程序图标。如果加载了 http 处理程序列表,则表示 web.config 有效
  • 在最近的版本中,您应该使用如下配置部分:&lt;section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK" /&gt;。我建议您包含带有错误代码的完整错误消息(例如0x{hex number}),因为该问题将更易于阅读和分析。
  • 好的 - 我从带有 IISExpress 的 VisualStudio 2017 运行。我认为这实际上是一个 VS2017 配置问题。我将改为在 IIS 上运行它。
  • Tetsuya - 当您说“最新版本”时,您是什么意思?什么版本?点网?

标签: asp.net paypal web-config


【解决方案1】:

我想通了。它与权限、IISExpress 或其他任何东西无关,而与该部分中的位置无关。我将元素移动到元素下方,不再有错误。去图吧。

<configuration>
  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>
...

我过去编写了自己的 XML 解析器,它读取整个文件并且不依赖于元素的顺序(只要它遵循结构并且存在所需的元素)。我错误地认为 web.config 文件中的顺序无关紧要。很高兴知道(将来可能会省去很多程序员的麻烦)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-24
    • 2015-07-20
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    相关资源
    最近更新 更多