Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to hide connection string information in web.config file in c#.net?
Please reply with an example.

[EDIT] changed the subject [/EDIT]
Posted
Updated 31-Jan-11 18:58pm
v3

You can hide the connection string by encrypting it in web.config.

See it with example here http://msdn.microsoft.com/en-us/library/ms998283.aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Feb-11 0:56am    
It looks like a better suggestion - my 5.
--SA
RaviRanjanKr 1-Feb-11 0:59am    
Nice Answer Amit.
take my 5
Pravin Patil, Mumbai 1-Feb-11 1:04am    
Take my 5...
TweakBird 1-Feb-11 1:05am    
Good link.
Wild-Programmer 1-Feb-11 1:41am    
Thanks everyone :)
If you mean making web.config file invisible for system users, it would make in invisible for your application. If you make it visible for your application, it means any user having sufficient privileges will be able to read. You can only work-around it not having connection string at all in this file. For example, you could specially design ciphered storage (say, based on XML file), decode it on the fly and code assignment of you connection string programmatically in your application.

Can this idea help you?

—SA
 
Share this answer
 
v4
Comments
RaviRanjanKr 1-Feb-11 1:00am    
Excellent Idea SA
Sergey Alexandrovich Kryukov 1-Feb-11 1:18am    
You mean deleting this? :-)
RaviRanjanKr 1-Feb-11 1:37am    
No! SA
I read your answer and i think it can be a good idea to invisible web.config. that's why i voted 5
OriginalGriff 1-Feb-11 1:42am    
Do you want me to delete this for you? You should be high enough level to do that yourself - have you not got a Red "X" near "Improve Answer"?
If you want it gone, just tell me, and I'll do the deed!
Sergey Alexandrovich Kryukov 1-Feb-11 2:47am    
I actually requested to delete by this flag.
--SA
Encryption will be the best approach to hide the information. Why the connection string kind of information stored in webconfig in, there is no need to compile the code again if its changed and its ease to access globally. If Encryption/Decryption method is followed be extra care while you changing the userid and password in the string.

And for example you can refer this article [^] . It may help you :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900