Encrypting parts of web.config file in asp.net

In order to encrypt the parts of web.config file, esp: connectionStrings section the following command can be executed

Note down the name of the site in the IIS Web Server [Ex: ConnectionStringEncryptionTest]

Open windows command prompt as an administrator,

Execute the following command

C:\Windows\system32>%systemroot%\system32\inetsrv\APPCMD list site “ConnectionSt
SITE “ConnectionStringEncryptionTest” (id:4,bindings:http/*:99:,state:Started)

CD to the directory where the source code resides, and then execute the following command from a Visual Studio command prompt, again running as “Administrator”

aspnet_regiis.exe -pe "connectionStrings" -app "/" -site "4"

In case of the site being hosted in the default web site, we can use the “-app” parameter alone instead of the -site parameter.





Encryption Note 1


To restore a Database from a bak file

In order to restore a database that was backed up from an existing server or a remote server, the following sql command can be used


RESTORE DATABASE [MyDb] FROM DISK=’C:\Program Files\Microsoft SQL Server\MSSQL11.LOCAL\MSSQL\Backup\MyDb.bak’
WITH MOVE ‘MyDb’ TO ‘C:\Program Files\Microsoft SQL Server\MSSQL11.LOCAL\MSSQL\DATA\MyDbdata.mdf’, MOVE ‘CelloV45_log’ TO ‘C:\Program Files\Microsoft SQL Server\MSSQL11.LOCAL\MSSQL\DATA\MyDblog.ldf’

Using IIS Express from the Command Line

The following code snippet can be used to run the IIS Express [8.0] in my case to be run from the command line.

The parameters are the path to the main directory, the target libraries [dll’s] should be in a folder ┬ácalled as “bin” inside this given path for the IIS to pick up and run.

The other parameter is the “port” which specifies which port should IIS Express listen for the incoming request. It also logs in the requests and the response status etc in the command line.

Sample :┬ác:\Program Files\IIS Express>iisexpress.exe /path:”C:\Users\Saravanan\Documents\Visual Studio 2012\Projects\console_app_in_iis\console_app_in_iis” /port:8089