0

I have one solution with two projects one web application and one windows azure project.
To link the two i made a right click in Roles>Add>Web Role Project in Solution.

All works great so far. I am able to test the application through compute emulator on multiple instances and test it locally as well if i click View in Browser.

I am aiming to keep the same code running both locally and in the cloud so, azure only code is enclosed within a block such as if(RoleEnvironment.IsAvailable) { } else { }

PROBLEM: The Web.config file is common to the web application and to the azure project and some configurations such as the TableStorageSessionStateProvider will not work locally so my question is...

<sessionState mode="Custom" customProvider="TableStorageSessionStateProvider">
    <providers>
        <clear/>
            <add name="TableStorageSessionStateProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider"/>
    </providers>
</sessionState>

QUESTION: Am i able to have two web.config files? One that is called when i browser the web site locally and one that is used when i test my application in compute emulator or when i deploy the solution to Microsoft Cloud?

ToinoBiclas
  • 262
  • 4
  • 13
  • 1
    As an aside, I wouldn't use the table storage session state provider in a production site as it has known issues. The hint is that the name space has .Samples. in it. For a full explanation see this answer: http://stackoverflow.com/questions/3940891/asp-net-mvc-azure-error-accessing-the-data-store/3952346#3952346 – knightpfhor Jun 09 '12 at 22:48
  • I'll keep that in mind... @knightpfhor do you recommend me to use database storage instead? – ToinoBiclas Jun 10 '12 at 00:27
  • I haven't had a chance to try it out yet, but I'd use the new distributed cache as it's the cheapest option: http://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/ If you don't want to take that risk, use SQL server – knightpfhor Jun 10 '12 at 01:54

2 Answers2

2

Try this answer to a similar question. You might be able to use Web.config transformations.

The idea would be to have your local testing in Web.config and then have a separate configuration in Web.cloud.config for cloud deployment.

Community
  • 1
  • 1
Peter K.
  • 8,028
  • 4
  • 48
  • 73
-1

No, you can't have more than one web.config. Transofrmations like mentioned by Peter do not work, as the transformation is not part of the azure packaging process.

If possible, try to set up as much as possible using code and RoleEnvironment.IsAvailable. Besides that you should try to avoid to have your config dependent to your machine.

If there's really no way around and you absolutely need different configuration files, you can set up an additional post-build task to replace the web.config file with a different one, when compiling in release mode.

  • You're right, transforms are not run as part of the packaging process, but they do run as part of the build process before the package is created. I've used this technique with success before. – knightpfhor Jun 09 '12 at 22:49
  • Transformation of `web.config` works perfectly when you publish your solution into Azure. – Rodolphe Sep 03 '12 at 16:05