开发者

Web.config in asp.net?

I have a doubt in my web application can i place two nework tags in smtp mailSetting tag. I PLACED in SMTP two network tags , BUT WHEN I AM SENDING MAIL I A开发者_运维技巧M GETTING THIS ERROR. The element may only appear once in this section. (C:\Inetpub\vhosts\example.com\httpdocs\web.config line 64) THIS IS MY WEB CONFIG CODE ......

<system.net>
<mailSettings>
  <smtp>
    <network host="webmail.example.com" port="25" userName="info@example.com"  Password="asdf"  defaultCredentials="false"/>
    <network host="webmail.yyy.com" port="25" userName="info@yyy.com"  Password="asdf254"  defaultCredentials="false"/>
  </smtp>
</mailSettings>


You can use the AppSettings section and add as many configuration values as you like. You can use for example:

<appSettings>
   <add key="SMTP1" value="smtpserver1"/>
   <add key="SMTP2" value="smtpserver2"/>
   <add key="SMTP3" value="smtpserver3"/>
   <add key="SMTP4" value="smtpserver4"/>
</appSettings>

and then in your code decide which server to use.


Nope you cannot. Though you can carry as many details in AppSettings section.


The SMTP details section is used to specify default values. To have more than one you need to write some code to read your own custom values from appsessings or even implement your own config section.


If you want different settings for different deployment configurations I would use Web.config Transformation. It was introduced in ASP.NET 4.0.

You can have one default setting for when you build the project on your localhost and when you publish it to the server, another one will be used.

Reference: http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜