开发者

Azure web role process not loading web.config?

I am running a web project in the Windows Azure Emulator and the web.config is not being loaded. I am running as a full IIS application, and I can go to the application running in IIS after the dev fabric has launched, and browse to the file location, and have verified that the correct web.config is indeed in the folder.

When I run my application, none of the standard appSetting keys, configuration,开发者_开发问答 or Enterprise library config is loaded. All data available to me is being pulled from the machine.config.

I have verified this by looking at the configuration manager data, the conn strings collection, and have lots of erros about not being able to get to my db as the default is not there and the only conn string is the local sql express server info from machine.config.


You can't normally access the web.config when the role is staring since it is running in another process. The Role Settings on your Role Properties (right-click your Role and select Properties, then select the Settings tab) is where you should have your role settings, you can access these from your role code like this:

RoleEnvironment.GetConfigurationSettingValue("MySetting")

If you still really want to use your web.config you might be able to do so by first right-clicking the web.config and selecting Copy if Newer, this will copy web.config to the System.Environment.CurrentDirectory which is where all the other role assembles lay. Then you can load it by using a XML reader and parse it yourself, I don't think WebConfigurationManager will help you as it expects a virtual path, so I suspect you would have to parse it yourself.


Actually, think this is a PEBCAK issue. I blindly followed an existing example in a different service we have, which is in a worker role, and happens to spawn a new exe process on the server as a hack to wrap a 32-bit 3rd party dll we need for some processing.

The new code I added directly attempts to process some messages from a queue in one of our web roles. The process that is executed is directly kicked off in the Run() method following the forever while loop, but the process expects access to the entire web.config (ENT LIB and EF) in order to work - and I am guessing that the code in the webrole does not exist in the same way as the application in te web role instance.

I am able to open up the site's web config following this example, but I am guessing I am going to need to make a separate worker role for this process. Shame, as it was a tiny process, but definitely kludgy.

Can anyone confirm that code executing in the webrole should not have access to the web.config? And by 'executing,' I mean the process is kicked off in Run(), but physically existing as a service in the hosted application. I guess this would be tantamount to expecting config items from a satellite assembly to automagically be present in the host process's config.

Bah! And if this is the case, does running this process as a worker role fix it? I can't find anything to explicitly deny or confirm my expectations...

I'll take a look here too - old - but looks almost identical - and suggests my web.config should be working:

http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/07e7dde7-0c0b-4497-8019-303a58759deb

UPDATE--- I created a worker role and moved the code there, and it worked as expected. So all i Wanted was a definitive - this will never work from a web role, so I emailed Steve Marx.

@stevemarx from personal communication - "Code in webrole.cs is running in a different process from the web application under IIS, and while you should certainly be able to open up web.config and read it (it’s just a file in the current directory), .NET won’t do anything special with web.config there. (It would be like putting a file called web.config in the same directory as a console app you were running.)"

So no, code in the webrole.cs process will not load my web.config.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜