【问题标题】:What is ConfigurationManager.AppSettings?什么是 ConfigurationManager.AppSettings?
【发布时间】:2017-06-03 09:48:42
【问题描述】:

我使用this 作为验证示例来试用。我想知道的是this 行中发生了什么。即ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"])。有人会好心解释一下吗?

【问题讨论】:

  • 存储在 web.config 中的信息?
  • @Lei Yang 哦,是的。 :) 谢谢。那么它是一个共同的价值还是我们可以改变它? ResourceId 的目的是什么?
  • 它是一种 .net 内置机制,用于在应用程序启动之前定义一些设置,无需重新编译。见msdn configurationmanager

标签: c# .net web-config configurationmanager


【解决方案1】:

您可以在 web.config 文件中为您的应用程序设置默认配置,并使用 ConfigurationManager.AppSettings 属性访问它们。

例如

web.config

<configuration>
    <appSettings>
        <add key="highestScore" value="200" />
        <add key="defaultSport" value="Cricket" />
    </appSettings>
</configuration>

代码

int maxScore = Convert.ToInt32(ConfigurationManager.AppSettings["highestScore"]);
string Sport = ConfigurationManager.AppSettings["defaultSport"].ToString();

【讨论】:

    【解决方案2】:

    您引用的 AuthBot 示例的 ActiveDirectory.ResourceId 应用设置是:

    <add key="ActiveDirectory.ResourceId" value="https://graph.windows.net/" />
    

    .ResourceId 是 graph.windows.net 而不是 graph.microsoft.com 的原因在这里解释了一些:https://github.com/matvelloso/AuthBot/pull/10

    它们都是有效的。这仅取决于您配置哪一个 在 AAD 中的应用程序。不是每个人都有 Office 365,因此没有 每个人都会有 graph.microsoft.com 所以我宁愿离开它 选择对大多数人更有效的选项 ——马特·韦洛索

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-08
      • 2010-12-27
      • 2010-09-28
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      相关资源
      最近更新 更多