BasicHttpContextBindingElement.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.Configuration;
  8. using System.Runtime.CompilerServices;
  9. using System.ServiceModel.Channels;
  10. [TypeForwardedFrom("System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  11. public partial class BasicHttpContextBindingElement : BasicHttpBindingElement
  12. {
  13. const string ContextManagementEnabledName = ContextBindingElementExtensionElement.ContextManagementEnabledName;
  14. public BasicHttpContextBindingElement()
  15. : base()
  16. {
  17. }
  18. public BasicHttpContextBindingElement(string name)
  19. : base(name)
  20. {
  21. }
  22. protected override Type BindingElementType
  23. {
  24. get { return typeof(BasicHttpContextBinding); }
  25. }
  26. [ConfigurationProperty(ContextManagementEnabledName, DefaultValue = ContextBindingElement.DefaultContextManagementEnabled)]
  27. public bool ContextManagementEnabled
  28. {
  29. get { return (bool)base[ContextManagementEnabledName]; }
  30. set { base[ContextManagementEnabledName] = value; }
  31. }
  32. protected internal override void InitializeFrom(Binding binding)
  33. {
  34. base.InitializeFrom(binding);
  35. BasicHttpContextBinding basicHttpContextBinding = (BasicHttpContextBinding)binding;
  36. SetPropertyValueIfNotDefaultValue(BasicHttpContextBindingElement.ContextManagementEnabledName, basicHttpContextBinding.ContextManagementEnabled);
  37. }
  38. internal override void InitializeAllowCookies(HttpBindingBase binding)
  39. {
  40. // do not emit allowCookies=true in generated config because BasicHttpContextBinding will always set AllowCookies to true anyway
  41. }
  42. protected override void OnApplyConfiguration(Binding binding)
  43. {
  44. base.OnApplyConfiguration(binding);
  45. if (this.ElementInformation.Properties["allowCookies"].ValueOrigin == PropertyValueOrigin.Default)
  46. {
  47. ((BasicHttpBinding) binding).AllowCookies = true;
  48. }
  49. else if (!this.AllowCookies)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.BasicHttpContextBindingRequiresAllowCookie, this.Name, ""));
  52. }
  53. ((BasicHttpContextBinding)binding).ContextManagementEnabled = this.ContextManagementEnabled;
  54. }
  55. }
  56. }