HttpRuntimeConfigurationHandler.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // System.Web.Configuration.HttpRuntimeConfigurationHandler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Configuration;
  12. using System.Security.Cryptography;
  13. using System.Xml;
  14. namespace System.Web.Configuration
  15. {
  16. class HttpRuntimeConfigurationHandler : IConfigurationSectionHandler
  17. {
  18. public object Create (object parent, object context, XmlNode section)
  19. {
  20. if (section.HasChildNodes)
  21. ThrowException ("Child nodes not allowed here", section.FirstChild);
  22. HttpRuntimeConfig config = new HttpRuntimeConfig (parent);
  23. config.ExecutionTimeout = AttUIntValue (section, "executionTimeout", 90);
  24. config.MaxRequestLength = AttUIntValue (section, "maxRequestLength", 4096);
  25. config.RequestLengthDiskThreshold = AttUIntValue (section, "requestLengthDiskThreshold", 256);
  26. config.UseFullyQualifiedRedirectUrl = AttBoolValue (section, "useFullyQualifiedRedirectUrl", false);
  27. config.MinFreeThreads = AttUIntValue (section, "minFresThreads", 8);
  28. config.MinLocalRequestFreeThreads = AttUIntValue (section, "minLocalRequestFreeThreads", 4);
  29. config.AppRequestQueueLimit = AttUIntValue (section, "appRequestQueueLimit", 100);
  30. config.EnableKernelOutputCache = AttBoolValue (section, "requestLengthDiskThreshold", true);
  31. config.EnableVersionHeader = AttBoolValue (section, "requestLengthDiskThreshold", true);
  32. config.RequireRootSaveAsPath = AttBoolValue (section, "requestLengthDiskThreshold", true);
  33. config.IdleTimeout = AttUIntValue (section, "requestLengthDiskThreshold", 20);
  34. config.Enable = AttBoolValue (section, "requestLengthDiskThreshold", true);
  35. config.VersionHeader = AttValue (section, "versionHeader");
  36. return config;
  37. }
  38. //
  39. static bool AttBoolValue (XmlNode node, string name, bool _default)
  40. {
  41. string v = AttValue (node, name);
  42. if (v == null)
  43. return _default;
  44. bool result = (v == "true");
  45. if (!result && v != "false")
  46. ThrowException ("Invalid boolean value in " + name, node);
  47. return result;
  48. }
  49. static int AttUIntValue (XmlNode node, string name, int _default)
  50. {
  51. string v = AttValue (node, name);
  52. if (v == null)
  53. return _default;
  54. int result = 0;
  55. try {
  56. result = (int) UInt32.Parse (v);
  57. } catch {
  58. ThrowException ("Invalid number in " + name, node);
  59. }
  60. return result;
  61. }
  62. static string AttValue (XmlNode node, string name)
  63. {
  64. return HandlersUtil.ExtractAttributeValue (name, node, true);
  65. }
  66. static void ThrowException (string message, XmlNode node)
  67. {
  68. HandlersUtil.ThrowException (message, node);
  69. }
  70. //
  71. }
  72. }