.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Encrypt App.config for SMTP settings

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :.NET Framework

Hi all,

I need to encrypt SMTP settings in the app.config file.I also read MSDN article that uses RSA also to encrypt/decrypt.
This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace EncryptionDecryptionCA
  public class Program
    private static void ProtectConfiguration()
      // Get the application configuration file.
      Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

      // Define the Rsa provider name.
      string provideRsa = "RsaProtectedConfigurationProvider";


View Complete Post

More Related Resource Links

What will be the correct smtp settings for sending out email from an asp.net website to gmail's bus

Hi,I have setup a gmail's business account for my company.Now I want to receive all the emails like ContactUs, Qoute Email, etc from my website to that account i.e. info@mydomainname.com I have added the following smtp settings behind my web formsSmtpClient smtpClient = new SmtpClient("localhost",25); //Providing Network credentials smtpClient.Credentials = new System.Net.NetworkCredential("quote@mydomainname.com", "password"); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage mail = new MailMessage(); //HTML Mail Format mail.IsBodyHtml = false; //Setting Form , To and CC mail.From = new MailAddress("quote@mydomainname.com", "My Web Site"); mail.To.Add(new MailAddress("info@mydomainname.com")); This code gives me feedback "email has successful sent"  but it does not send any email to info@mydomainname.comCan anyone let me know what will be the correct smtp settings for sending out emails to gmail's business accounts?Regards,Dazy

Using web.config settings in a


Hi there,

I understand that one can specify a connection string in an <asp:SqlDataSource /> tag, like so:

<asp:SqlDataSource ID="sds" runat="server" ConnectionString="<%$ ConnectionStrings:LiveConnectionString %>" SelectCommand="SELECT Col1 FROM MyTable"></asp:SqlDataSource>

Is there a similar way to specify the table used in the SELECT command?  The following doesn't work for me:

<asp:SqlDataSource ID="sds" runat="server" ConnectionString="<%$ ConnectionStrings:LiveConnectionString %>" SelectCommand="SELECT Col1 FROM <%$ AppSettings:NewContentsListSQLTable %>"></asp:SqlDataSource>

I see from a previous post (http://forums.asp.net/p/1325626/2646097.aspx) that it's possible to set parameter values from web.config settings, so I'd hope you could specify the table (or columns etc.) as well!

All advice gratefully received.

Convert user.config to database storage via my custom settings provider



I've created my own custom settings provider to save user settings (formerly in the user.config) to a database. To point the particular settings that are to be saved to the database I specified

for each property to point to the BlobSettingsProvider instead of allowing them to default to the LocalFileSettingsProvider.
Now I need to convert existing user.configs to save to the database on the fly - a one time conversion. Because I've now specified the properties to use the BlobSettings provider they can no longer access the local user.config.
Does anyone have any thoughts on how best to accomplish this conversion (i.e. read the local user.config and populate the BlobSettingsProvider). The app can be run as a ClickOnce installed app or as a simple .net app - finding the correct local user.config looks to be a problem.
Thoughts, ideas,...?


encrypt App.config

How can I encrypt the entire App.config instead of encrypting just the aaSetting or ConnectionStrings only?

Jassim Rahma

First WCF Connection Slow and Proxy Settings in app.config file


I'm new to the WCF and currently facing problems with my first connection to a service we created to connect an Excel OBA to SAP. The first connection is extremely slow, approximately 20 seconds, but once it is establish everything goes really quick afterwards. I've read through some posts and seems like the proxy settings could have an impact. I'm pasting the code of my app.config file below, can you please let me know how I should modify it to include proper proxy settings to improve the first connection?

Also, the proxy thing is just a guess, is there anything else I could do to improve this? Any hint would be appreciated.

Thanks a lot!






xml version

Reconnect WCF klient useing app.config settings




I have a webservice with a reconnect button in the client. I'd like to implement the reconnect function. I have seen a lot of example how to reconnect but all of them implements it with setting the endpoint and everything in the code.

When open my client it uses the app.config settings to open the WCF channel. Actually I'm not a developer so I don't really understand how. I just instantiating my implemented webservice class and it do the job itself.

Is it possible to reopen channel / reconnect using the app.config settings without setting everything in code? Or do I have to set in the code every parameter?




I'm not a development! I'm an infrastructure engineer! Please be patient on the development forums! :)

hard code app.config settings in class



I wonder how to hard code the configuration below in a class. I have a case where I cannot use app.config (due to creation of dll).  The code below is probably not enough..any help is appreciated. Thanks in advance.

hard coded in class

ContractDescription contract = new ContractDescription("Common.MyInterfaces.IConnector");

Binding binding = new NetTcpBinding();

binding.Name = "net.tcp.binding";

EndpointAddress endPointAddress = new EndpointAddress("net.tcp://localhost:9001/Connector");

ServiceEndpoint serviceEndpoint = new ServiceEndpoint(contract, binding, endPointAddress);






        <binding name="net.tcp.binding"></binding>





        <behavior name

web.config has incorrect settings for the requestFiltering element


HI! When I upgrade from wss 3.0 to sharepoint foundation 2010, i find this error and the error is shown below:

Web.config file has incorrect settings for the requestFiltering element.

The requestFiltering element in web.config must have the allowDoubleEncoding attribute set to true in order to support file names with the + character in them. Also, it must have a child requestLimits element with the maxAllowedContentLength attribute set to 2147483647 to avoid interfering with file uploads.

Ensure the requestFiltering element exists in web.config, that its allowDoubleEncoding attribute is set to true, that it has a child requestLimits element, and that its maxAllowedContentLength is set to 2147483647. For more information about this rule, see "http://go.microsoft.com/fwlink/?LinkID=163442".


In the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\web.config, the maxAllowedContentLength is already set to 2147483647. 

Does anyone have any idea?


Service throttling behaviour app.config settings

How can I calculate the MaxConcurrentSessions, MaxConcurrentCalls and maxConcurrentInstances properties to set in the app.config ? I believe it should have some dependency on the # of CPU and the Max and Min worker threads based on which these parameters can be set.

Can you please guide me how can I provide them the number for these properties like we could calculate for ASP.NET.

Unable to encrypt web.config connectionStrings in web application project


 I'm all set on the server side with the RSA key pair installed. Where I'm hung up is trying to get the job done on the web.config file ... can't seem to get the aspnet_regiis command string right. I am using the command string provided by the web host (DiscountAsp.net). Most (all) of the examples I read use a website on the development machine. I actually registered my project in IIS and tried that but it didn't work. In any case I would rather not have to go to the hassle of registering a project in IIS anyway if I can avoid it.


My web application project is in a folder on my local machine:

D:\Projects\<project name>

This is most recent (failed) attempt to use aspnet_regiis:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -pe "connectionStrings" "D:\Projects\<project name>"

Is it possible to just do this manually by looking at the NetFrameworkConfigurationKey_xxxxx.xml file and entering the values? Seems like it should be do-able except I'm not sure how to parse the xml file for the correct values.

On a related note, when I add the following code to web.config it "announces" that "The keyContainerName attribute is not allowed". Ditto useMachineContainer

    <configProtectedData defaultP

Encrypt connection strings in web config




We have website hosted on shared server with SQL Server 2005 as database. Now that database server is also shared by other people and hence we have to use SQL Server authentication and we have stored those connection strings in our web.config file.


Can we encrypt connection strings? I found few ways to encrypt but in all of them I have to have access to the server and that I don't have.


Pls help.



Clean Web.Config Files (VS 2010 and .NET 4.0 Series)

.NET 4 includes a new version of the CLR, and a new .NET 4 specific machine.config file (which is installed side-by-side with the one used by .NET 2, .NET 3 and .NET 3.5).

The new .NET 4 machine.config file now automatically registers all of the ASP.NET tag sections, handlers and modules that we've added over the years, including the functionality for:

.ASP.NET Dynamic Data
.ASP.NET Routing (which can now be used for both ASP.NET WebForms and ASP.NET MVC)
.ASP.NET Chart Control (which now ships built-into ASP.NET V4)
What this means is that when you create a new "Empty ASP.NET application" project in VS 2010, you'll find that the new default application-level web.config file is now clean and simple:

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Convert English to Arabic number without changing any regional settings in .net

Well, most applications that I worked with was multilingual that supports English UI and Arabic UI.

And one of the major issue that we have faced is displaying Arabic numbers without the need of changing the regional settings of the PC.

So the code below will help you to display Arabic number without changing any regional settings.

validateRequest appears to be kicking in in MVC RC1 despite settings

After upgrading a project to the RC a System.Web.HttpRequestValidationException is thrown when posting a value containing HTML from a TextArea. I have checked that validateRequest=false in Views/web.config, and have set this in the application's root web.config. I have also created a fresh MVC project, created a simple view & controller and posted a simple html paragraph element with the same result. Call stack provided. [HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (html="

hello world

").] System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName) +8718538 System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName) +111 System.Web.HttpRequest.get_Form() +129 System.Web.HttpRequestWrapper.get_Form() +11 System.Web.Mvc.ValueProviderDictionary.PopulateDictionary() +113 System.Web.Mvc.ValueProviderDictionary..ctor(ControllerContext controllerContext) +74 System.Web.Mvc.ControllerBase.get_ValueProvider() +31 System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +53 System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +109 System.W

reading values from config files in NUnit tests


One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?

NUnit and config files


Ive created an NUnit test project in my solution and have added 3 tests.  They all fail with the same error

SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.


SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.

  ----> System.NullReferenceException : Object reference not set to an instance of an object.

heres the test method

        public void CreateDataContext_ConnectionString_ReturnsDataCon
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend