Blog de l'équipe support IIS/Azure France -- French IIS/Azure Support Team Blog

Blog for the French IIS/Azure/ Support Team dealing with various toppics related to IIS, web development and Azure (Web Sites, Web Roles)

WebRole entry point and config file…

WebRole entry point and config file…

Rate This
  • Comments 1

When you write a web role requiring application specific configuration (like assembly binding), you may have a hard time trying to figure out which app configuration file should be used and how to get it deployed and used in your role. This issue has been hit by many developers and raised in many blogs & forums:

The key point to remember is that full IIS web role entry point (code implemented in WebRole.cs) is loaded into the WaIISHost.exe process and not w3wp.exe. Therefore, you can't expect settings defined in web.config to be used in you role entry point.

There are 2 solutions to this issue :

These are the steps you can use for the second option in Visual Studio :

  1. In solution explorer, click on your web role project (WebRole1 in this example) and select Add -> Web Configuration File
  2. Name the configuration file <webrole name>.dll.config (in this example, WebRole1.dll.config)
  3. Setup the config file content depending on your needs (assembly redirection…etc)
  4. Build the Azure package and deploy it to Azure

Alternatively to the above approach, you can use a "Before build" action to copy the web.config to bin\<webrole name>..dll.config :

copy $(ProjectDir)Web.config $(TargetDir)$(TargetFileName).config

Using the context menu, you'll then need to include in the project the bin\<webrole name>.dll.config. With this approach, you'll be able to set all you settings in a single file (web.config).

With the above steps, you should end up with the web role config file copied to the /bin directory of your webrole (E:\sitesroot\0\bin). In case, it isn't, you may also check that the configuration file is present in the package created (open the cspkg file as a zip file and confirm that the config file is present under the path : WindowsAzure1.cspkg\WebRole1_<ID>.cssx\approot\bin\).

I would like to thank Mr Claus Nielsen for having reported the issue and spending time to troubleshoot it with Microsoft Support…

Emmanuel Boersma

Leave a Comment
  • Please add 1 and 7 and type the answer here:
  • Post
  • A note for anybody trying to use the pre-build command above, ensure the commands are encased in quotes if your project directory has spaces, else the command will not work.

    copy "$(ProjectDir)Web.config" "$(TargetDir)$(TargetFileName).config"

Page 1 of 1 (1 items)