在Web.config文件外存储SMTP [英] Storing SMTP outside the Web.Config File

查看:127
本文介绍了在Web.config文件外存储SMTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在我的存储连接,应用程序设置在外部文件中,只是通过引用我的web.config该文件。这个作品真的很好,因为它可以让我保持独立的连接字符串和应用程序设置。这是非常方便的,因为我在开发过程中发现我会经常做出许多改变webconfig,我讨厌每次我需要更新我的web.config时间来管理环境的具体数值。

For some time now I've been storing my connection and app settings in an external file and just referencing that file via my web.config. This works really well because it allows me to keep separate connection strings and app settings. This is really handy since I find during development I will often make many changes to the webconfig and I hate having to manage the environment specific values every time I need to update my web.config.

反正是有,我可以做到这一点与他SMTP配置节在web.config中。

Is there anyway I can achieve this with he SMTP configuration sections in the web.config.

推荐答案

当然,你可以使用configSource属性。

Sure, you can use the configSource attribute.

例如:

<system.net>
  <mailSettings>
   <smtp configSource="MailSettings.config"/>
  </mailSettings>
</system.net>

然后把你的mailSettings配置数据MailSettings.config

Then put your mailSettings configuration data in MailSettings.config

于是你MailSettings.config文件将有类似:

So then your MailSettings.config file would have something like:

    <network 
    host="relayServerHostname" 
    port="portNumber"
    userName="username"
    password="password" />

更新:看起来像它可能需要实际上是在SMTP节点去正常工作,所以我已经更新上面的code来表示 - 同样的想法,仅这一项应该工作。 :)

Update: looks like it may need to actually go in the smtp node to work properly, so I've updated the above code to indicate that - same idea, only this one should work. :)

这篇关于在Web.config文件外存储SMTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆