ASP.NET/.NET interview Question – How will you do encryption of connection strings in web.config file?

Answer: When you host your site on server, sometimes happens that your site is handled
by an third party or any other individual who is responsible to handle the
server. As your site is handled or manage by another person it can be possible
for that person to view your connection string and can make changes to the
same. So in order avoid this we need to encrypt your connection string.This can be achieved by using aspnet_regiis tool provided by the ASP.NET.

It’s a very simple 3 steps process.

Step 1:- Let first define the connection string in web.config file like below
code snippet.

<connectionStrings>

<connectionStrings>
<add name=”Constr” connectionString=”Data Source=localhost;Initial Catalog=YourDataBaseName;    Integrated Security=True”/>
</connectionStrings>

In the above snippet code you can see that the connection string easily
visible by anyone because it is in decrypted format. Hence to prevent or protect the connection string we need to encrypt connection string in such a way that it is not visible to anyone.

Step 2: – Just go to Visual Studio Command Prompt and use spnet_regiis tool to encrypt the defined connection string like below diagram.
e1.png

Now just execute the Visual Studio Command Prompt and if the encryption is done successfully a message will be displayed like below diagram.

e2.png

Step 3:- Go to web.config file and you will see that connection string is
now in encrypted format like below diagram.

e3.png
You will be also interested in watching the below video, which are also
asked in most of the interviews and favourable question of interviewers.


Please click here to see more ASP.NET and .NET interview questions

Regards,

Visit Authors blog for more  ASP.NET/.NET interview questions
Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s