Guest User

Untitled

a guest
Dec 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using (var server = new ServerManager())
  2. {
  3. try
  4. {
  5. Site site = server.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"];
  6. string physicalPath = site.Applications["/"].VirtualDirectories["/"].PhysicalPath;
  7. string webConfigPath = Path.Combine(physicalPath, "web.config");
  8.  
  9. var doc = System.Xml.Linq.XDocument.Load(webConfigPath);
  10.  
  11. var redisCacheProviderSettings = doc.Descendants("sessionState").Single().Descendants("providers").Single().Descendants("add").Single();
  12.  
  13. redisCacheProviderSettings.SetAttributeValue("host", RoleEnvironment.GetConfigurationSettingValue("SessionRedisCacheHost"));
  14. redisCacheProviderSettings.SetAttributeValue("accessKey", RoleEnvironment.GetConfigurationSettingValue("SessionRedisCacheAccessKey"));
  15. redisCacheProviderSettings.SetAttributeValue("ssl", "true");
  16. redisCacheProviderSettings.SetAttributeValue("throwOnError", "false");
  17.  
  18. doc.Save(webConfigPath);
  19. }
  20. catch (Exception ex)
  21. {
  22. // Log error
  23. }
  24. }
Add Comment
Please, Sign In to add comment