配置文件错误 [英] Configuration file error

查看:160
本文介绍了配置文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试从外部应用程序加密我的web.config文件.奇怪的是,该应用程序可以在Windows 7 PC和Server 2003上运行,但是我在Server 2008上始终收到以下错误:无法为请求的配置对象创建配置文件.这是我正在使用的代码:

Hi all,

I am trying to encrypt my web.config file from an external application. The strange thing is that the application works on my Windows 7 PC as well as Server 2003, but I keep receiving the following error on Server 2008: Configuration file cannot be created for the requested configuration object. Here is the code that I am making use of:

System.Configuration.Configuration webconfig = WebConfigurationManager.OpenWebConfiguration("/WebService1") as System.Configuration.Configuration;
webconfig.ConnectionStrings.ConnectionStrings.Clear();
webconfig.ConnectionStrings.ConnectionStrings.Add(new System.Configuration.ConnectionStringSettings("connection",
	string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}", item.DataSource, item.InitialCatelog, item.Username, item.Password)));
System.Configuration.ConfigurationSection section = webconfig.GetSection(webconfig.ConnectionStrings.SectionInformation.SectionName);
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
webconfig.Save(System.Configuration.ConfigurationSaveMode.Modified);



为什么我仅在Server 2008上收到错误的任何指针?
提前非常感谢.
问候,



Any pointers to why I am only receiving the error on Server 2008?
Many thanks in advance.
Kind regards,

推荐答案

看起来像是访问权限问题.如果已托管,请验证您是否已授予IIS的权限,或者验证ASP.NET是否有权访问该文件并对其进行修改.

另外,运行:
Looks like an access permission issue. Verify you had given permissions to IIS if hosted or ASP.NET to access the file and modify it.

Also,run:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe


好吧,事实证明该问题是由错误的虚拟路径和网站名称引起的.

修复OpenWebConfiguration的ctor中的参数,一切正常.
感谢您的答复.

亲切的问候,
Well turns out that the issue was caused by an incorrect virtual path and website name.

Fix the parameters in the ctor of the OpenWebConfiguration and everything worked.
Thanks for the responses.

Kind regards,


这篇关于配置文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆