SessionStateSectionHandler.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. if (section.Attributes != null && section.Attributes.Count > 0)
  43. HandlersUtil.ThrowException ("Unknown attribute.", section);
  44. return config;
  45. }
  46. // A few methods to save some typing
  47. static string AttValue (string name, XmlNode node, bool optional)
  48. {
  49. return HandlersUtil.ExtractAttributeValue (name, node, optional);
  50. }
  51. static string AttValue (string name, XmlNode node)
  52. {
  53. return HandlersUtil.ExtractAttributeValue (name, node, true);
  54. }
  55. static void ThrowException (string message, XmlNode node)
  56. {
  57. HandlersUtil.ThrowException (message, node);
  58. }
  59. //
  60. }
  61. }