从APP.config加密或删除连接字符串 [英] Encrypting or Removing Connection String from APP.config
本文介绍了从APP.config加密或删除连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网站正在从 APP.config文件而不是从web.config获取连接字符串.
app.config的结构如下:
Hi,
I have a website which is taking connection string from APP.config file not web.config.
the structure of app.config as follows:
<config>
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl = "true" />
</system.web>
<appSettings>
<services>
<dataServices>
<dataService>
<srvcName>TESTDBNAME</srvcName>
<srvcAddress>111.111.11.X</srvcAddress>
<srvcUserName>sa</srvcUserName>
<srvcPassword>sa</srvcPassword>
</dataService>
</<services>
</appSettings>
</<config>
我们使用如下所示的应用程序配置连接数据库
we connect DB using app config like below
public static ArrayList GetNodeText(string xpath)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("App.config");
XPathDocument xPathDocument = new XPathDocument(stringBuilder.ToString());
XPathNavigator xpathNavigator = xPathDocument.CreateNavigator();
return SnXmlUtil.GetValuesFromXPath(xpathNavigator, xpath);
}
public static string GetSnNexDbConnStr()
{
StringBuilder stringBuilder = new StringBuilder();
string str = Convert.ToString(GetNodeText("/config/appSettings/services/dataServices/dataService/srvcName")[0]);
string str2 = Convert.ToString(GetNodeText("/config/appSettings/services/dataServices/dataService/srvcAddress")[0]);
string str3 = Convert.ToString(SnXmlUtil.GetNodeText("/config/appSettings/services/dataServices/dataService/srvcUserName")[0]);
string str4 = Convert.ToString(GetNodeText("/config/appSettings/services/dataServices/dataService/srvcPassword")[0]);
stringBuilder.Append("database=" + str + ";");
stringBuilder.Append("Server=" + str2 + ";");
if (!str.Contains("_Local"))
{
stringBuilder.Append("uid=" + str3 + ";");
stringBuilder.Append("pwd=" + str4 + ";");
}
else
{
stringBuilder.Append("Integrated Security=True;");
}
return stringBuilder.ToString();
}
this is main code to get the values from app.config
我的问题是:
我们正在使用上面的应用程序文件连接到数据库.所以我如何将上面的凭据隐藏或加密到外部app.config文件中,并且如果我们在运行时对应用程序文件进行加密,会话是否会变为null?
My Question is:
we are connecting to database using above app file.so how can i hide or encrypt the above credential in app.config file to outside the world.And does session will become null if we encrypt app file at runtime.
推荐答案
请参阅:
http://msdn.microsoft.com/en-us/library/zhhddkxy.aspx [ ^ ],
http://stackoverflow.com/questions/1593923/如何从代码隐藏在网络配置中写入连接字符串 [
Please see:
http://msdn.microsoft.com/en-us/library/zhhddkxy.aspx[^],
http://stackoverflow.com/questions/1593923/how-to-encrypt-connectionstring-written-in-web-config-from-codebehind[^].
—SA
这篇关于从APP.config加密或删除连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文