SessionStateSectionHandler.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // System.Web.SessionState.SessionStateSectionHandler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.Configuration;
  11. using System.Web.Configuration;
  12. using System.Xml;
  13. namespace System.Web.SessionState
  14. {
  15. class SessionStateSectionHandler : IConfigurationSectionHandler
  16. {
  17. public object Create (object parent, object context, XmlNode section)
  18. {
  19. //TODO: context?
  20. SessionConfig config = new SessionConfig (parent);
  21. if (section.HasChildNodes)
  22. ThrowException ("No children nodes allowed", section);
  23. string attvalue = AttValue ("mode", section, false);
  24. if (!config.SetMode (attvalue))
  25. ThrowException ("Invalid mode value", section);
  26. if (section.Attributes == null)
  27. return config;
  28. attvalue = AttValue ("cookieless", section);
  29. if (attvalue != null)
  30. if (!config.SetCookieLess (attvalue))
  31. ThrowException ("Invalid cookieless value", section);
  32. attvalue = AttValue ("timeout", section);
  33. if (attvalue != null)
  34. if (!config.SetTimeout (attvalue))
  35. ThrowException ("Invalid timeout value", section);
  36. attvalue = AttValue ("stateConnectionString", section);
  37. if (attvalue != null)
  38. config.SetStateConnectionString (attvalue);
  39. attvalue = AttValue ("sqlConnectionString", section);
  40. if (attvalue != null)
  41. config.SetSqlConnectionString (attvalue);
  42. attvalue = AttValue ("stateNetworkTimeout", section);
  43. if (attvalue != null)
  44. config.SetStateNetworkTimeout (attvalue);
  45. if (section.Attributes != null && section.Attributes.Count > 0)
  46. HandlersUtil.ThrowException ("Unknown attribute.", section);
  47. return config;
  48. }
  49. // A few methods to save some typing
  50. static string AttValue (string name, XmlNode node, bool optional)
  51. {
  52. return HandlersUtil.ExtractAttributeValue (name, node, optional);
  53. }
  54. static string AttValue (string name, XmlNode node)
  55. {
  56. return HandlersUtil.ExtractAttributeValue (name, node, true);
  57. }
  58. static void ThrowException (string message, XmlNode node)
  59. {
  60. HandlersUtil.ThrowException (message, node);
  61. }
  62. //
  63. }
  64. }