【问题标题】:How do i get a specific value from the config file [duplicate]如何从配置文件中获取特定值 [重复]
【发布时间】:2019-11-14 03:37:48
【问题描述】:

您好,我收到了以下app.config。 我如何获取 smtp 服务器邮件主题等的值。

string filePath = ConfigurationManager.AppSettings["SmtpServer"]; i'm getting nothing

实际上添加的键值也返回null。

【问题讨论】:

标签: asp.net app-config


【解决方案1】:

很简单

1st 你这样设置web.config 或app.config 文件值。

<appSettings>
<add key="SmtpServer" value="abc" />
</appSettings>

然后获取价值。

string filePath = Convert.ToString(ConfigurationManager.AppSettings["SmtpServer"]);

或者 同 app.config 文件

 string filePath = System.Configuration.ConfigurationManager.AppSettings["SmtpServer"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    • 2020-11-01
    • 2018-07-17
    • 1970-01-01
    相关资源
    最近更新 更多