开发者

How to protect the connectionstring in web.config?

开发者 https://www.devze.com 2023-01-22 06:25 出处:网络
I have a website about to go live. I\'m wondering what I should be doing about the connectionstring in the web.config. 开发者_JS百科Do I obfuscate it and it so how?

I have a website about to go live. I'm wondering what I should be doing about the connectionstring in the web.config. 开发者_JS百科Do I obfuscate it and it so how?

Thanks!


The standard method is to encrypt it. http://ondotnet.com/pub/a/dotnet/2005/02/15/encryptingconnstring.html

However, another good option is to store it in the registry and set the permissions so that only the asp.net runtime can access it.

See this article: http://msdn.microsoft.com/en-us/library/ff649224.aspx and this KB: http://support.microsoft.com/kb/821616

Although I do have to say that using the registry does tend to complicate deployment and using text/staging servers a bit. We did it... ONCE and then went back to encrypting.


You can encrypt the <connectionStrings> section in your web.config - see How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI


Here is an example for the same; http://whatilearnttuday.blogspot.in/2012/02/use-of-configurationproviders-to.html


Since you didn't provide any information about this in your question I will assume you have credentials in your connection string.

From a security perspective you should try to avoid this, use Windows Authentication if possible. Obviously this requires that you have access to an Active Directory environment and all the servers are deployed in it.

If not, it's always better to lock down the web-server instead of trying to make sure that files on disk are secure from tampering by different users.

If even this is not possible then I would follow the approach given by the other replies, encrypting the sensitive content with DPAPI.


You could simply encrypt your entire web.config file:

See the steps here:

http://www.proworks.com/blog/archive/encrypting-your-webconfig/

0

精彩评论

暂无评论...
验证码 换一张
取 消