本文介绍了如何以编程方式检索的web.config的SMTP服务器的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有存储在web.config中 <以下SMTP细节; system.net> < mailSettings> <从=isds@ixtent.com> SMTP; <网络主机=mail.domain.com端口=25的userName =用户名密码=密码的DefaultCredentials =真/> < / SMTP> < / mailSettings> < /system.net> 我如何从一个C#类中检索这些值。 解决方案 配置的ConfigurationFile = WebConfigurationManager .OpenWebConfiguration(〜/的web.config); MailSettingsSectionGroup mailSettings =的ConfigurationFile .GetSectionGroup(system.net/mailSettings)作为MailSettingsSectionGroup; 如果(mailSettings!= NULL) { INT端口= mailSettings.Smtp.Network.Port; 字符串主机= mailSettings.Smtp.Network.Host; 字符串密码= mailSettings.Smtp.Network.Password; 串的用户名= mailSettings.Smtp.Network.UserName; } I have the following SMTP details stored in web.config<system.net> <mailSettings> <smtp from="isds@ixtent.com"> <network host="mail.domain.com" port="25" userName="username" password="password" defaultCredentials="true"/> </smtp> </mailSettings> </system.net>How can I retrieve these values from within a c# class. 解决方案 Configuration configurationFile = WebConfigurationManager .OpenWebConfiguration("~/web.config");MailSettingsSectionGroup mailSettings = configurationFile .GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;if (mailSettings != null){ int port = mailSettings.Smtp.Network.Port; string host = mailSettings.Smtp.Network.Host; string password = mailSettings.Smtp.Network.Password; string username = mailSettings.Smtp.Network.UserName;} 这篇关于如何以编程方式检索的web.config的SMTP服务器的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!