locked
DistributedCacheSessionStateStoreProvider and DistributedCacheOutputCacheProvider... using .config only? RRS feed

  • Question

  • The two provided .DLL's appear to be hard-coded to use .config settings only to get information about the cache account.

    Is it possible to get account-specific settings from .cscfg file?  How?  This seems like a big oversight if such capability is not supported.

     


    Auto-scaling & monitoring service for Windows Azure applications at http://www.paraleap.com
    Wednesday, October 26, 2011 7:01 PM

Answers

  • We attached to the DistributedCacheSessionStateStoreProvider.CacheConnecting event. You should note that the configuration provider will validate the authorization token value, so you will need a legit value in the web.config.
            void Application_Start(object sender, EventArgs e)
            {
                // Code that runs on application startup
    
                var cacheNamespace = RoleEnvironment.GetConfigurationSettingValue("Cache.Namespace");
                var authToken = RoleEnvironment.GetConfigurationSettingValue("Cache.AuthToken");
                const int cachePort = 22233;
    
                DistributedCacheSessionStateStoreProvider.CacheConnecting += (s, args) =>
                    {
                        var servers = new List<DataCacheServerEndpoint> { new DataCacheServerEndpoint(string.Format("{0}.cache.windows.net", cacheNamespace), cachePort) };
                        args.CacheFactoryConfiguration.Servers = servers;
                        args.CacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(Global.CreateSecureString(authToken));
                    };
            }
    
            static private SecureString CreateSecureString(String token)
            {
                var secureString = new SecureString();
                foreach (char c in token)
                {
                    secureString.AppendChar(c);
                }
                secureString.MakeReadOnly();
                return secureString;
            }
    
     
    • Proposed as answer by Trent Swanson Thursday, January 26, 2012 1:00 AM
    • Marked as answer by Igor Papirov Thursday, January 26, 2012 1:59 AM
    Wednesday, January 25, 2012 9:19 AM

All replies

  • Hi Igor,

    Have you seen the blogpost by Vittorio Bertocci on how to add and edit the WIF configuration in the web.config in Azure? I know this is not a complete answer to your question, but it might point you in the right direction. In your case it's a matter of finding the .config file you need to edit.

     


    With regards,

    Patriek

    www.patriekvandorp.net
    If this reply is of help to you, please don't forget to mark it as an answer.
    Wednesday, October 26, 2011 8:20 PM
  • Thanks Patriek!  I was also considering changing web.config on the fly but still am hoping for a more elegant solution.  Changing web.config on start seems very hack-ish.
    Auto-scaling & monitoring service for Windows Azure applications at http://www.paraleap.com
    Thursday, October 27, 2011 4:58 AM
  • Hi,

    Actually, ASP.NET does not support programmatically configuring session/cache providers (without some hackings such as reflection). Thus it is difficult for you to configure anything related to the ACS providers in code. Since this is an ASP.NET limitation, you can submit a feature request on http://forums.asp.net/1239.aspx/1?ASP+NET+4+5+ASP+NET+WCF+and+Visual+Studio+11+Developer+Previews. ASP.NET team is gathering feedback on the next version, so now it is a good time to submit feature requests. You can also submit a more general feature request (request Windows Azure to allow you to modify web.config without upgrading the deployment) on http://www.mygreatwindowsazureidea.com/forums/34192-windows-azure-feature-voting.

     

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Monday, October 31, 2011 2:59 AM
  • Ming Xu,

     

    Thanks for your reply.  I am not looking to programmatically configure cache & session providers.  I simply want to hook into Azure's logic that will safely reboot my instances when .cscfg change occurs.  If Azure AppFabric cache providers were to read from .cscfg, such run-time switch to another cache account would be possible w/o taking the site down.


    Auto-scaling & monitoring service for Windows Azure applications at http://www.paraleap.com
    Monday, October 31, 2011 6:05 AM
  • Hi,

    Do you mean you want to restart the instance when cscfg changes, you can handle the RoleEnvironment.Changing event, and set e.Cancel to true. Refer to http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changing.aspx for more information. But note currently you cannot configure cache accounts in cscfg. You have to do that in web.config.

     

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Monday, October 31, 2011 10:36 AM
  • We attached to the DistributedCacheSessionStateStoreProvider.CacheConnecting event. You should note that the configuration provider will validate the authorization token value, so you will need a legit value in the web.config.
            void Application_Start(object sender, EventArgs e)
            {
                // Code that runs on application startup
    
                var cacheNamespace = RoleEnvironment.GetConfigurationSettingValue("Cache.Namespace");
                var authToken = RoleEnvironment.GetConfigurationSettingValue("Cache.AuthToken");
                const int cachePort = 22233;
    
                DistributedCacheSessionStateStoreProvider.CacheConnecting += (s, args) =>
                    {
                        var servers = new List<DataCacheServerEndpoint> { new DataCacheServerEndpoint(string.Format("{0}.cache.windows.net", cacheNamespace), cachePort) };
                        args.CacheFactoryConfiguration.Servers = servers;
                        args.CacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(Global.CreateSecureString(authToken));
                    };
            }
    
            static private SecureString CreateSecureString(String token)
            {
                var secureString = new SecureString();
                foreach (char c in token)
                {
                    secureString.AppendChar(c);
                }
                secureString.MakeReadOnly();
                return secureString;
            }
    
     
    • Proposed as answer by Trent Swanson Thursday, January 26, 2012 1:00 AM
    • Marked as answer by Igor Papirov Thursday, January 26, 2012 1:59 AM
    Wednesday, January 25, 2012 9:19 AM
  • Thank you! This is it!
    Auto-scaling & monitoring service for Windows Azure applications at http://www.paraleap.com
    Thursday, January 26, 2012 1:59 AM