appcmd可以修改web.config以使用redis进行会话吗?

时间:2015-10-27 20:23:11

标签: iis appcmd

鉴于以下iis web.config

<add name="FooProvider..

您如何使用appcmd更改<sessionState customProvider>的值?

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

<add name="FooProvider"

但我不知道如何将<add name="BarProvider"更改为 appcmd set config 'mycompany/mysite' -section:system.web/sessionState /-"providers.[name='RedisSessionStateStoreProvider']

我可以删除提供程序,我可以添加提供程序,但是因为我使用CHEF自动执行此操作,我需要一种幂等的方法,并且可以连续多次运行。

删除提供商

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

创建提供者

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

清除提供商

    import pythoncom, pyHook

def OnKeyboardEvent(event):
    print 'MessageName:',event.MessageName
    print 'Message:',event.Message
    print 'Time:',event.Time
    print 'Window:',event.Window
    print 'WindowName:',event.WindowName
    print 'Ascii:', event.Ascii, chr(event.Ascii)
    print 'Key:', event.Key
    print 'KeyID:', event.KeyID
    print 'ScanCode:', event.ScanCode
    print 'Extended:', event.Extended
    print 'Injected:', event.Injected
    print 'Alt', event.Alt
    print 'Transition', event.Transition
    print '---'

# return True to pass the event to other handlers
    return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

如何在不删除和重新创建提供程序的情况下修改提供程序的值?

1 个答案:

答案 0 :(得分:0)

我不相信这是可能的,但是我能够通过使用CHEF可以对资源进行有条件的“通知”这一事实来解决这个问题。如果web.config文件发生变化,我只能通过“通知”来保留幂等性。

作为参考,这些是有效的命令。

Redis配置

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'