Setting multiple SMTP settings in web.config?

I needed to have different smtp configurations in the web.config depending on the environment: dev, staging and production. Here’s what I ended up using: In web.config: <configuration> <configSections> <sectionGroup name=”mailSettings”> <section name=”smtp_1″ type=”System.Net.Configuration.SmtpSection”/> <section name=”smtp_2″ type=”System.Net.Configuration.SmtpSection”/> <section name=”smtp_3″ type=”System.Net.Configuration.SmtpSection”/> </sectionGroup> </configSections> <mailSettings> <smtp_1 deliveryMethod=”Network” from=”[email protected]”> <network host=”…” defaultCredentials=”false”/> </smtp_1> <smtp_2 deliveryMethod=”Network” from=”[email protected]”> <network host=”1…” defaultCredentials=”false”/> … Read more

Log4Net “Could not find schema information” messages

You can bind in a schema to the log4net element. There are a few floating around, most do not fully provide for the various options available. I created the following xsd to provide as much verification as possible: http://csharptest.net/downloads/schema/log4net.xsd You can bind it into the xml easily by modifying the log4net element: <log4net xsi:noNamespaceSchemaLocation=”http://csharptest.net/downloads/schema/log4net.xsd” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>

How do I store a dictionary object in my web.config file?

Why reinvent the wheel? The AppSettings section is designed for exactly the purpose of storing dictionary-like data in your config file. If you don’t want to put too much data in your AppSettings section, you can group your related values into their own section as follows: <configuration> <configSections> <section name=”MyDictionary” type=”System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ /> … Read more

The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015

I had this issue despite having all the correct configuration. It turned out to be some bad files in the Component Cache, preventing the Razor views from recognising ViewBag, Model, and HtmlHelpers. Deleting these files solved the problem (good versions of these files were created next time I opened Visual Studio). The files are located … Read more

How do I use Web.Config transform on my connection strings?

This works for me but I too have found it to be a bit flakey at times. You will need to create another file called Web.Config.Release and fill it with the following: <configuration xmlns:xdt=”http://schemas.microsoft.com/XML-Document-Transform”> <connectionStrings> <add name=”local” connectionString=”Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword” xdt:Transform=”SetAttributes” xdt:Locator=”Match(name)”/> </connectionStrings> <system.web> <compilation xdt:Transform=”RemoveAttributes(debug)” /> </system.web> <appSettings> <add key=”default_db_connection” value=”local” xdt:Transform=”SetAttributes” xdt:Locator=”Match(key)” … Read more

Encrypting Web.Config

Here are the commands to encrypt web.config file without any programming… For encryption aspnet_regiis -pef “Section” “Path exluding web.config” For Decryption aspnet_regiis -pdf “Section” “Path exluding web.config” From this commands you can encrypt or decrypt all the section.