0
我有一个应用程序在未经授权的异常情况下更改webconfig中的连接字符串。有没有办法让我可以访问文件?谢谢你的帮助。更改XML文件时收到未经授权的异常
异常消息:System.UnauthorizedAccessExeption:访问路径“路径”被拒绝。 //文件路径xml文件
var adminConnectionStringConfig = new FileInfo(e.Data.Details.VSStudio.Solution.FullName).Directory
+ @"\Web.Admin\ConnectionStrings.config";
//Method that updates the xml file
private void SetupConnectionStrings(string path, string newDb)
{
var doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.SelectSingleNode("configuration/connectionStrings");
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Attributes["name"].Value == "SYS")
{
//Get ConnectionString for client project
var connectionString = node.ChildNodes[i].Attributes["connectionString"].Value;
// Cut all
var dbName = node.ChildNodes[i].Attributes["connectionString"]
.Value.Substring(connectionString.IndexOf("Catalog="));
dbName = dbName.Replace("Catalog=", "");
//Db Name that we will now replace
dbName = dbName.Substring(0, dbName.IndexOf(";"));
// System.Diagnostics.Debugger.Launch();
doc.InnerXml = doc.InnerXml.Replace(dbName, newDb);
doc.Save(path);
break;
}
}
}
什么是异常消息? – SLaks
添加了外观 – user516883
异常在哪里? –