0

Given the following iis web.config

<sessionState customProvider="Foo" mode="Custom" timeout="90">
  <providers>
    <add name="FooProvider" type="Redis"/>
  </providers>
</sessionState>

How would you change the values of <add name="FooProvider.. with appcmd?

I'm able to change the <sessionState customProvider>

appcmd.exe set config 'mycompany/mysite' -section:system.web/sessionState -customProvider:"bar" -timeout:90

But I don't know how to change <add name="FooProvider" to <add name="BarProvider"

I can delete the provider, and I can add a provider, however because I'm using CHEF to automate this, I need a way that is idempotent and can be run multiple times in a row.

Delete provider

 appcmd set config 'mycompany/mysite' -section:system.web/sessionState /-"providers.[name='RedisSessionStateStoreProvider']

Create provider

 appcmd set config 'mycompany/mysite' -section:system.web/sessionState /+"providers.[type='Redis',name='RedisSessionStateStoreProvider']"

Clear provider

appcmd clear config 'mycompany/mysite' -section:system.web/sessionState /providers

How can I modify the value of a provider without deleting and recreating it?

spuder
  • 17,437
  • 19
  • 87
  • 153

1 Answers1

0

I don't believe this is possible, however I was able to work around it by using the fact that CHEF can do conditional "notify" of resources. I was able to preserve idempotence by only 'notifying' if the web.config file changes.

For reference, these are the commands that work.

Redis config

appcmd clear config 'MyCompany/mysite' '-section:system.web/sessionState'
appcmd.exe set config 'MyCompany/mysite' '-section:system.web/sessionState' '-mode:Custom' '-timeout:90' '-customProvider:RedisSessionStateStoreProvider'
appcmd set config 'MyCompany/mysite' '-section:system.web/sessionState' /+"providers.[name='RedisSessionStateStoreProvider',connectionString='10.10.10.10:6379,connectTimeout=5000,abortConnect=false,ssl=false',type='RedisAspNetProviders.SessionStateStoreProvider, RedisAspNetProviders']"

Sql config

appcmd clear config 'MyCompany/mysite' '-section:system.web/sessionState'
appcmd.exe set config 'MyCompany/mysite' '-section:system.web/sessionState' '-mode:SQLServer' '-allowCustomSqlDatabase:true' '-sqlConnectionString:network=dbmssocn; initial catalog=ASPState; user id=webfarmsession; connection lifetime=100;max pool size=200;data source=10.254.50.51; failover partner=10.254.50.50; password=xxxxxx' '-cookieless:false' '-timeout:90'
spuder
  • 17,437
  • 19
  • 87
  • 153