Can we encrypt external appSettings and connectionStrings in web.config? - asp.net

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings configSource="appSettings.config"/>
<connectionStrings configSource="connections.config"/>
<system.web>
<compilation debug="true" />
<authentication mode="Windows"/>
<identity impersonate="true"/>
</system.web>
</configuration>
Above web.config is used in MVC Web Application.
I tried to encrypt using RsaProtectedConfigurationProvider with aspnet_regiis. But it's not working as expected in simple Web.config where appSettings and connectionStrings present at the same file.
I am using the command to encrypt web.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pef "connectionStrings" "D:\WebApplication" -prov "AppEncryptionProvider".
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pef "appSettings" "D:\WebApplication" -prov "AppEncryptionProvider".
but while using this in a web application it gives me the error as below: Failed to decrypt using provider 'AppEncryptionProvider'. Error message from the provider: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
Line 1: <appSettings configProtectionProvider="AppEncryptionProvider">
Line 2: <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
Line 3: xmlns="http://www.w3.org/2001/04/xmlenc#">
Line 4: <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />

Yes. You can do this with the below command by passing provider and your site name.
aspnet_regiis -pe "appSettings" -prov "{0}" -site {1} -app "/"
Where:
{0} is the name of your encryption provider specified in the web.config.
{1} is the Id of your site in IIS
Similar Question:
Encrypting AppSettings in file external to Web.Config

Related

How to encrypt the connectstring section of web.config in MVC website?

i want to encrypt the connectionstring section of my web.config. i have tried to do this by following the below steps:
Open Developer Command Prompt for VS2013
aspnet_regiis -pef "connectionStrings" -app "/E:\New folder\WebApplication1\WebApplication1"
it is thorwing me error "a configuration file cannot be created for the requested configuration object. failed"
I did some google but i am not able to get why i am facing this. i have tried to change the permissions of website folder?
do i need to set the website in IIS?
please help me to solve this issue.
thanks in advance.
<configuration>
<configProtectedData defaultProvider="SampleProvider">
<providers>
<add name="SampleProvider"
type="System.Configuration.RsaProtectedConfigurationProvider,
System.Configuration, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL"
keyContainerName="SampleKeys"
useMachineContainer="true" />
</providers>
add above section into web.config.
Open Developer Command Prompt for VS2013
change directory to C:\Windows\Microsoft.NET\Framework\v4.0.30319 using
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
run the following command
aspnet_regiis -pef "connectionStrings" "E:\New folder\WebApplication2\WebApplication2"
It encrypt the connection string. :)

connect asp.net with postgreSQL

I am tryig to connect my asp.net project to a postgres database.
My webconfig file:
<configuration>
<connectionStrings>
<add name="con" connectionString="Driver={PostgreSQL};Server=localhost;Port=5432;Database=demo;Uid=postgres;Pwd=postgres; "/>
</connectionStrings >
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
my connection code:
using (NpgsqlConnection connection = new NpgsqlConnection())
{
connection.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ToString();
It is throwing error:
Could not load file or assembly 'Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
How to solve this?
I also have install postgres odbc driver and created a system dsn. If Possible How to use that?
Please check the link below :
http://bytes.com/topic/postgresql/answers/778355-using-npgsql-net

How to encrypt Connection Strings credentials in Web.Config file in ASP.Net

I'm working on asp.net project I have to encrypt credential in web.config file
<add name="ConnectionString"
connectionString="Data Source=sqlexpress;
Initial Catalog=Employee;
User ID=testUser;
Password=testPassword"
providerName="System.Data.SqlClient"/>
You can use aspnet_regiis to do this.
As an example:
aspnet_regiis -pe "connectionStrings" -app "/SampleApplication" -prov "RsaProtectedConfigurationProvider"
Encrypting and Decrypting Configuration Sections

Error while encrypting connection string (The configuration section 'connection1' was not found.)

C:\WINDOWS\Microsoft.NET\Framework\v2.0>aspnet_regiis.exe -pef connection1
"C:\Website1" -prov "RSAProtectedConfigurationProvider"
Encrypting configuration section...
The configuration section 'connection1' was not found.
Failed!
Above is screen shot of error that i getting while encrypting connection string
The web config file is as,
<configuration>
<connectionStrings>
<add name="connection1" connectionString="Data Source=inpun2-s4pvh8bs;uid=cusa;pwd=csusa;Initial Catalog=ChemTrack"/>
</connectionStrings>
</configuration>
Any idea about this?
I am running this from visual studio 2010 command prompt.
also a/c that i am using is member of administrator group.
Try this instead :
aspnet_regiis.exe -pef "connectionStrings" "C:\Website1"
For more : http://www.codeproject.com/Tips/304638/Encrypt-or-Decrypt-Connection-Strings-in-web-confi

asp site will not work when uploading to web server?

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="rde_410978ConnectionString" connectionString="Data Source=SQL2008.net.dcs.hull.ac.uk;Initial Catalog=rde_410978;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
Here is my config file. I'm publishing it to the server by going to build > publish website.
None of the errors are due to the server as the university has set it up and it's working correctly for other people.
the error:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Source Error:
Line 16:
Line 17: <system.web>
Line 18: <compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
Line 19:
Line 20: <authentication mode="Forms">
Source File: C:\RDEUsers\NET\410978\web.config Line: 18
Did you check IIS?
Sometimes IIS is set to a different framework.
http://technet.microsoft.com/en-us/library/cc754523(v=ws.10).aspx
Here is a similar problem and solution:
http://forums.asp.net/t/1491204.aspx/1
I think its because of the .net version of the Deployment Environment, which I presume is not 4.0.
Check it up with others if they have the same target Framework listed i.e. 4.0.

Resources