-1

有人可以告诉我如何system.net/mailSettings在 ASP.NET 中设置全局配置吗?

如果我在 IIS 管理器的 GUI 中更改它,文件:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config

被改变。

有没有办法通过Microsoft.Web.Administration命名空间访问这个文件?

4

1 回答 1

0

我知道了:

System.Configuration.Configuration webconfig = System.Web.Configuration.WebConfigurationManager.OpenMachineConfiguration();
System.Net.Configuration.MailSettingsSectionGroup mailSection = webconfig.GetSectionGroup("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;
mailSection.Smtp.From = "aspx@defaultmail.com";
mailSection.Smtp.Network.Host = Service.Config.SMTP_SERVER;
mailSection.Smtp.Network.Port = Service.Config.SMTP_PORT;
webconfig.Save(System.Configuration.ConfigurationSaveMode.Modified);
于 2013-11-01T08:10:42.353 回答