Skip to main content
 首页 » 编程设计

c#之Asp.net mvc web.config 和 web.debug.config 区别

2024年01月24日30freeliver54

我的 visual studio 解决方案窗口中有 Web.config 和 Web.debug.config 和 Web.release.config 文件。

我想为发布和调试设置不同的电子邮件配置。

所以我设置了Web.debug.config文件

  <system.net> 
    <mailSettings> 
      <smtp deliveryMethod="SpecifiedPickupDirectory"> 
        <network host="localhost" port="587" defaultCredentials="true"/> 
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Debug"/> 
      </smtp> 
    </mailSettings> 
  </system.net> 

然后我设置我的 Web.release.config

  <system.net> 
    <mailSettings> 
      <smtp deliveryMethod="SpecifiedPickupDirectory"> 
        <network host="localhost" port="587" defaultCredentials="true"/> 
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Release"/> 
      </smtp> 
    </mailSettings> 
  </system.net> 

当我运行应用程序时,我的设置不会加载到 SmtpClient 对象。

为什么不从 Web.debug.config 获取设置

请您参考如下方法:

这仅在您发布 项目时有效,在 IDE 中无效。在这里阅读更多内容:

https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx