2013-11-01 38 views
-1

有人能告訴我如何在ASP.NET中設置全局system.net/mailSettings配置嗎?如何更改全局.NET system.net/mailSettings配置?

如果我改變它在IIS管理器的GUI文件:

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

改變。

有沒有辦法通過Microsoft.Web.Administration命名空間訪問此文件?

回答

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 = "[email protected]defaultmail.com"; 
mailSection.Smtp.Network.Host = Service.Config.SMTP_SERVER; 
mailSection.Smtp.Network.Port = Service.Config.SMTP_PORT; 
webconfig.Save(System.Configuration.ConfigurationSaveMode.Modified);