我可以从我的Azure Web角色切入点访问的web.config?我的、切入点、角色、Azure

2023-09-03 17:14:54 作者:多少不堪

我有一个Azure的Web角色,我想存储在&LT在web.config中的一些设置;的appSettings> 标记。是的,我所知道的服务配置文件,但我有理由preFER web.config文件。

I have an Azure web role and I want to store some settings in web.config under <appSettings> tag. Yes, I'm aware of service configuration files, yet I have reasons to prefer web.config.

当我执行(从这里):

System.Configuration.Configuration rootWebConfig =
    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
if (rootWebConfig1.AppSettings.Settings.Count > 0) {
}

设置数始终为零,虽然我已经添加一个键值对下&LT;的appSettings&GT;

我是什么做错了吗?是否有可能从内部Web角色切入点读取web.config设置?

What am I doing wrong? Is it possible to read settings from web.config from inside web role entry point?

推荐答案

这样做的原因是因为Azure的SDK 1.3,微软已经推出了完整的IIS功能。 这样做的副作用是,RoleEntryPoint被从Web应用程序的其它部分用墙隔开了。

The reason for this is that Microsoft has introduced Full IIS capability since Azure SDK 1.3. A side effect of this is that the RoleEntryPoint gets walled off from the rest of the web application.

这是微软的博客文章描述你所看到的。

The following excerpt from Microsofts blog post describes what you're seeing.

...有完整的IIS,在RoleEntryPoint下运行的 WaIISHost.exe ,而该网站在一个正常的IIS 的w3wp.exe 的进程中运行。

...with full IIS, the RoleEntryPoint runs under WaIISHost.exe, while the web site runs under a normal IIS w3wp.exe process.

...因此,预计其配置是在一个名为 WaIISHost.exe.config文件。因此,如果您创建的Web项目名称的文件,并设置复制到输出目录属性设置为一直拷贝,你会发现,RoleEntryPoint可以愉快地阅读。

...so it expects its configuration to be in a file called WaIISHost.exe.config. Therefore, if you create a file with this name in the your web project and set the "Copy to Output Directory" property to "Copy Always" you'll find that the RoleEntryPoint can read this happily.

除了提到的解决方案,一种选择可能是尝试使用托管Web核心(HWC)模式,而不是完整的IIS模式。

Apart from the solution mentioned, an option might be to try to use Hosted Web Core (HWC) mode instead of full IIS mode.

的Azure SDK 1.3 -1.7会看在 WaIISHost.exe.config

的Azure SDK 1.8+会看在 WebRoleProjectName.dll.config 。

Azure SDK 1.8+ will look in the WebRoleProjectName.dll.config.

使用最新的改变SDK,您应该能够放置的的app.config 的在你的项目,你的角色的切入点应该再访问它。

With the newest change to the SDK, you should be able to place an app.config in your project and your role entry point should then have access to it.