WinForm和WebForm下读取config中邮件配置的方法

1.  在WinForm下?取 App.config中的?件配置?句如下:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);//OpenExeConfiguration2 ?方法的??我也?搞清楚到底?怎么用。
MailSettingsSectionGroup mailSettings = .NetSectionGroup.GetSectionGroup(config).MailSettings;

App.config代?如下:

<?Xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.Net>
        <mailSettings>
        <smtp from="[email protected]">
            <.Network  host="smtp.wmdev.mobi"
            userName="admin"
            password="password"/>
        </smtp>
       </mailSettings>
    </system.Net>
</configuration>

2.  在WebForm下?取Web.config中的?件配置代?如下:

Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");
MailSettingsSectionGroup mailSettings = (MailSettingsSectionGroup)config.GetSectionGroup("system.Net/mailSettings"); //此?的"system.Net/mailSettings“如果改成其他????取其他的相?的配置信息
Web.config代?如下:

与App.config一?

<?Xml version="1.0" ?>
<configuration>
    <system.Net>
        <mailSettings>
        <smtp from="[email protected]">
            <.Network  host="smtp.wmdev.mobi"
            userName="admin"
            password="password"/>
        </smtp>
       </mailSettings>
    </system.Net>
</configuration>

你可能感兴趣的:(xml,.net,Web,webform,WinForm)