C# 从外部 dll 读取 web.config 中的 <system.net><mailSettings>

标签 c# dll smtp web-config

我的网络应用调用外部 dll。在 dll 中,我想访问 system.net/mailSettings/smtp 部分中指定的 PickupDirectory pickupDirectoryLocation 值。我如何从 dll 代码中获取它?

有点像

System.Configuration.ConfigurationSettings.GetConfig("configuration/system.net/mailSettings/smtp/specifiedPickupDirectory/pickupDirectoryLocation")

但这行不通

最佳答案

您可以使用:

public string GetPickupDirectory()
{
    var config = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;

    return (config != null) ? config.SpecifiedPickupDirectory : null;
}

关于C# 从外部 dll 读取 web.config 中的 <system.net><mailSettings>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3265888/

相关文章:

c++ - 错误 C2732 : linkage specification contradicts earlier specification for 'log'

delphi - 对 smtp.live.com 和 TIdSmtp(Indy、Delphi)的 SSL 支持

c# - 如何使用 asp.net core/react 发布数据

c# - 如何使用 LINQ 检查所有项目是否属于同一类型

c# - Facebook c# sdk Fork : Version5 oAuth

dll - 如何判断一个库是COM还是DCOM?

Java JNI,dll的多个版本: How to specify which dll is being used for native calls (matlab jvm)

java - 使用 JavaMail 发送邮件 - 端口 25、STARTTLS、身份验证

java - 在 Java EE 中安全存储 SMTP 凭证

c# - Azure 通知中心错误 401