The Labs \ Source Viewer \ SSCLI \ System.Net.Configuration \ HttpWebRequestElement

  1. //------------------------------------------------------------------------------
  2. // <copyright file="HttpWebRequestElement.cs" company="Microsoft Corporation">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net.Configuration
  16. {
  17.     using System;
  18.     using System.Configuration;
  19.     using System.Reflection;
  20.     using System.Security.Permissions;
  21.    
  22.     public sealed class HttpWebRequestElement : ConfigurationElement
  23.     {
  24.         public HttpWebRequestElement()
  25.         {
  26.             this.properties.Add(this.maximumResponseHeadersLength);
  27.             this.properties.Add(this.maximumErrorResponseLength);
  28.             this.properties.Add(this.maximumUnauthorizedUploadLength);
  29.             this.properties.Add(this.useUnsafeHeaderParsing);
  30.         }
  31.        
  32.         protected override void PostDeserialize()
  33.         {
  34.             // Perf optimization. If the configuration is coming from machine.config
  35.             // It is safe and we don't need to check for permissions.
  36.             if (EvaluationContext.IsMachineLevel)
  37.                 return;
  38.            
  39.             PropertyInformation[] protectedProperties = {ElementInformation.Properties[ConfigurationStrings.MaximumResponseHeadersLength], ElementInformation.Properties[ConfigurationStrings.MaximumErrorResponseLength]};
  40.            
  41.             foreach (PropertyInformation property in protectedProperties)
  42.                 if (property.ValueOrigin == PropertyValueOrigin.SetHere) {
  43.                     try {
  44.                         ExceptionHelper.WebPermissionUnrestricted.Demand();
  45.                     }
  46.                     catch (Exception exception) {
  47.                         throw new ConfigurationErrorsException(SR.GetString(SR.net_config_property_permission, property.Name), exception);
  48.                     }
  49.                 }
  50.         }
  51.        
  52.         protected override ConfigurationPropertyCollection Properties {
  53.             get { return this.properties; }
  54.         }
  55.        
  56.        
  57.         [ConfigurationProperty(ConfigurationStrings.maximumUnauthorizedUploadLength, DefaultValue = (int)(-1))]
  58.         public int MaximumUnauthorizedUploadLength {
  59.             get { return (int)this[this.maximumUnauthorizedUploadLength]; }
  60.             set { this[this.maximumUnauthorizedUploadLength] = value; }
  61.         }
  62.        
  63.         [ConfigurationProperty(ConfigurationStrings.MaximumErrorResponseLength, DefaultValue = (int)(64))]
  64.         public int MaximumErrorResponseLength {
  65.             get { return (int)this[this.maximumErrorResponseLength]; }
  66.             set { this[this.maximumErrorResponseLength] = value; }
  67.         }
  68.        
  69.        
  70.         [ConfigurationProperty(ConfigurationStrings.MaximumResponseHeadersLength, DefaultValue = 64)]
  71.         public int MaximumResponseHeadersLength {
  72.             get { return (int)this[this.maximumResponseHeadersLength]; }
  73.             set { this[this.maximumResponseHeadersLength] = value; }
  74.         }
  75.        
  76.         [ConfigurationProperty(ConfigurationStrings.UseUnsafeHeaderParsing, DefaultValue = false)]
  77.         public bool UseUnsafeHeaderParsing {
  78.             get { return (bool)this[this.useUnsafeHeaderParsing]; }
  79.             set { this[this.useUnsafeHeaderParsing] = value; }
  80.         }
  81.        
  82.         ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
  83.        
  84.         readonly ConfigurationProperty maximumResponseHeadersLength = new ConfigurationProperty(ConfigurationStrings.MaximumResponseHeadersLength, typeof(int), 64, ConfigurationPropertyOptions.None);
  85.        
  86.         readonly ConfigurationProperty maximumErrorResponseLength = new ConfigurationProperty(ConfigurationStrings.MaximumErrorResponseLength, typeof(int), 64, ConfigurationPropertyOptions.None);
  87.        
  88.         readonly ConfigurationProperty maximumUnauthorizedUploadLength = new ConfigurationProperty(ConfigurationStrings.maximumUnauthorizedUploadLength, typeof(int), -1, ConfigurationPropertyOptions.None);
  89.        
  90.         readonly ConfigurationProperty useUnsafeHeaderParsing = new ConfigurationProperty(ConfigurationStrings.UseUnsafeHeaderParsing, typeof(bool), false, ConfigurationPropertyOptions.None);
  91.     }
  92. }

Developer Fusion