Hi,
Is it good from security point of view to create a separate class for connection and use it? or save the connection string in web.config file... Which is the best method?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jiteendra SampathiraoPosted May 24, 2011, 7:14 AM
Retrive the values based on
Suthish NairPosted May 24, 2011, 7:12 AM
1. xml file (1.xml)..
2. fetch the ConnectionString
Label1.Text = GetConnectionStringKey("ConnectionString")
3. method to read the xml file, Lot of ways to read the xml.
Different ways of reading an XML file
You can store any config settings and later retrieve..
Posted May 24, 2011, 7:08 AM
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\ConnectionString.xml");
XmlNode xn = xmlDoc.SelectSingleNode("ConnectionString");
connStr = xn.InnerText;
Later you can use the "connStr" variable in your application.
Kavita BPosted May 24, 2011, 6:59 AM
If we store the connection string in XML file... How to access it? I never tried it before so plzzz help
Jiteendra SampathiraoPosted May 24, 2011, 5:36 AM
As suthish said, .xml file is the very best option to store connection string value. But most of the people store the connection string in web.config file...
Suthish NairPosted May 24, 2011, 5:20 AM
The problem with storing connection strings in web.config is, whenever you update the web.config all the sessions get cleared/Killed which results in throwing out the users from web site.
So this can be avoided by using an .xml file for storing user credentials.
Remember to do file encryption/decryption if security is a concern.
Posted May 24, 2011, 4:57 AM
Moreover you can encrypt the connectionstring and you can store it into the configuration files also.
http://www.codeproject.com/KB/aspnet/webconfig.aspx
http://chiragrdarji.wordpress.com/2008/08/11/how-to-encrypt-connection-string-in-webconfig/
Ankit NandekarPosted May 24, 2011, 4:04 AM
These have some benefits :