如何以编程方式将 SMTP 服务器详细信息存储(保存)回 web.config
搜索 StackOverflow,我发现 这个关于如何检索 SMTP 的问题Web.Config 中的设置,但没有有关如何将 SMTP 更新回 web.config 文件的详细信息。
我从以下代码开始:
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
MailSettingsSectionGroup settings =
(MailSettingsSectionGroup)webConfig.GetSectionGroup("system.net/mailSettings");
SmtpSection smtp = settings.Smtp;
SmtpNetworkElement net = smtp.Network;
但 Intellisense 很快就提示 SmptSection.Network
是一个 Get(又名“只读”)访问器。
那么我应该如何以编程方式将 SMTP 数据写回 web.config 呢?
Searching StackOverflow, I found this question on how to Retrieve SMTP settings from Web.Config, but no details on how to update the SMTP back to the web.config file.
I started with the following code:
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
MailSettingsSectionGroup settings =
(MailSettingsSectionGroup)webConfig.GetSectionGroup("system.net/mailSettings");
SmtpSection smtp = settings.Smtp;
SmtpNetworkElement net = smtp.Network;
but was quickly clued in by Intellisense that SmptSection.Network
is a Get (aka "read-only") accessor.
So how am I supposed to programmatically write my SMTP data back to web.config?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该能够做这样的事情,这有效吗?:
You should be able to do something like this, does this work?:
看看这篇文章: http://www.west-wind.com/ WebLog/posts/8461.aspx
不过看起来您需要相当高的访问(权限)。
具体来自文章:
Take a look at this article: http://www.west-wind.com/WebLog/posts/8461.aspx
Looks like you need fairly high access (permissions) though.
Specifically from the article: