有人可以告诉我如何在ASP.NET中设置全局system.net/mailSettings
配置吗?
如果我在IIS管理器的GUI中更改了文件:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
已更改。
有没有办法通过Microsoft.Web.Administration
命名空间访问此文件?
答案 0 :(得分: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);