ServiceHostingEnvironmentSection.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Configuration;
  7. using System.Runtime;
  8. using System.Security;
  9. using System.Security.Permissions;
  10. using System.ServiceModel;
  11. public sealed partial class ServiceHostingEnvironmentSection : ConfigurationSection
  12. {
  13. public ServiceHostingEnvironmentSection()
  14. {
  15. }
  16. protected override void PostDeserialize()
  17. {
  18. // Perf optimization. If the configuration is coming from machine.config
  19. // It is safe and we don't need to check for permissions.
  20. if (EvaluationContext.IsMachineLevel)
  21. {
  22. return;
  23. }
  24. if (PropertyValueOrigin.SetHere ==
  25. ElementInformation.Properties[ConfigurationStrings.MinFreeMemoryPercentageToActivateService].ValueOrigin)
  26. {
  27. try
  28. {
  29. new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
  30. }
  31. catch (SecurityException)
  32. {
  33. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
  34. SR.GetString(SR.Hosting_MemoryGatesCheckFailedUnderPartialTrust)));
  35. }
  36. }
  37. }
  38. [ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
  39. public TransportConfigurationTypeElementCollection TransportConfigurationTypes
  40. {
  41. get { return (TransportConfigurationTypeElementCollection)base[ConfigurationStrings.DefaultCollectionName]; }
  42. }
  43. [ConfigurationProperty(ConfigurationStrings.BaseAddressPrefixFilters, Options = ConfigurationPropertyOptions.None)]
  44. public BaseAddressPrefixFilterElementCollection BaseAddressPrefixFilters
  45. {
  46. get { return (BaseAddressPrefixFilterElementCollection)base[ConfigurationStrings.BaseAddressPrefixFilters]; }
  47. }
  48. [ConfigurationProperty(ConfigurationStrings.ServiceActivations, Options = ConfigurationPropertyOptions.None)]
  49. public ServiceActivationElementCollection ServiceActivations
  50. {
  51. get { return (ServiceActivationElementCollection)base[ConfigurationStrings.ServiceActivations]; }
  52. }
  53. [ConfigurationProperty(ConfigurationStrings.AspNetCompatibilityEnabled, DefaultValue = false)]
  54. public bool AspNetCompatibilityEnabled
  55. {
  56. get { return (bool)base[ConfigurationStrings.AspNetCompatibilityEnabled]; }
  57. set { base[ConfigurationStrings.AspNetCompatibilityEnabled] = value; }
  58. }
  59. [ConfigurationProperty(ConfigurationStrings.CloseIdleServicesAtLowMemory, DefaultValue = false)]
  60. public bool CloseIdleServicesAtLowMemory
  61. {
  62. get { return (bool)base[ConfigurationStrings.CloseIdleServicesAtLowMemory]; }
  63. set { base[ConfigurationStrings.CloseIdleServicesAtLowMemory] = value; }
  64. }
  65. [ConfigurationProperty(ConfigurationStrings.MinFreeMemoryPercentageToActivateService, DefaultValue = 5)]
  66. [IntegerValidator(MinValue = 0, MaxValue = 99)]
  67. public int MinFreeMemoryPercentageToActivateService
  68. {
  69. get { return (int)base[ConfigurationStrings.MinFreeMemoryPercentageToActivateService]; }
  70. set { base[ConfigurationStrings.MinFreeMemoryPercentageToActivateService] = value; }
  71. }
  72. [ConfigurationProperty(ConfigurationStrings.MultipleSiteBindingsEnabled, DefaultValue = false)]
  73. public bool MultipleSiteBindingsEnabled
  74. {
  75. get { return (bool)base[ConfigurationStrings.MultipleSiteBindingsEnabled]; }
  76. set { base[ConfigurationStrings.MultipleSiteBindingsEnabled] = value; }
  77. }
  78. internal static ServiceHostingEnvironmentSection GetSection()
  79. {
  80. return (ServiceHostingEnvironmentSection)ConfigurationHelpers.GetSection(ConfigurationStrings.ServiceHostingEnvironmentSectionPath);
  81. }
  82. [Fx.Tag.SecurityNote(Critical = "Calls Critical method UnsafeGetSection which elevates in order to fetch config."
  83. + "Caller must guard access to resultant config section.")]
  84. [SecurityCritical]
  85. internal static ServiceHostingEnvironmentSection UnsafeGetSection()
  86. {
  87. return (ServiceHostingEnvironmentSection)ConfigurationHelpers.UnsafeGetSection(ConfigurationStrings.ServiceHostingEnvironmentSectionPath);
  88. }
  89. }
  90. }