Pergunta

I have setup the Web Roles to use colocated caching. The problem is that during development we don't want to have to run the emulator all the time (as it is quite cumbersome).

Running our web applications normally (not emulated in a Web Role) fails because of the Azure session state provider:

[InvalidOperationException: role discovery data is unavailable]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_Roles() +171

Is it possible to configure caching to use normal InProc when not running in a Web Role and to use Azure Colocated Caching when running in a Web Role.

Foi útil?

Solução

The session state configuration is located in the web.config, so you could create a config override with the standard web.config transformations for your local development and then when you deploy it make sure to switch to the config that has the reference to the Azure Caching provider.

http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx

UPDATE: Adding notes from comments below.
You can also add some code prior to the start of the website to programatically swap out the providers. There is the ability to do this on the web role start up (http://blog.elastacloud.com/2011/05/13/azure-howto-programmatically-modify-web-config-on-webrole-startup/) or with a simple (Synchronous) start up task. By doing this work in the role OnStart or the start up task you remove the necessity for the Asp.NET site to have a dependency on the Azure Runtime to detect if it is running in Azure or not and the config is completed before the IIS website is started.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top