Files
dotnet-bot adf899c629 Adding System.Data..., System.ServiceModel..., and System.Web...
Adding reference source for
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Xml
System.Xml.Linq
2016-05-03 00:07:37 +02:00

93 lines
3.4 KiB
C#

//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel
{
using System;
using System.ComponentModel;
using System.Configuration;
using System.Net.Security;
using System.Runtime.CompilerServices;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
[TypeForwardedFrom("System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public class BasicHttpContextBinding : BasicHttpBinding
{
bool contextManagementEnabled = ContextBindingElement.DefaultContextManagementEnabled;
public BasicHttpContextBinding()
: base()
{
this.AllowCookies = true;
}
public BasicHttpContextBinding(BasicHttpSecurityMode securityMode)
: base(securityMode)
{
this.AllowCookies = true;
}
public BasicHttpContextBinding(string configName)
: base()
{
if (configName == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("configName");
}
BasicHttpContextBindingCollectionElement section = BasicHttpContextBindingCollectionElement.GetBindingCollectionElement();
BasicHttpContextBindingElement element = section.Bindings[configName];
element.ApplyConfiguration(this);
if (element.ElementInformation.Properties["allowCookies"].ValueOrigin == PropertyValueOrigin.Default)
{
this.AllowCookies = true;
}
else if (!this.AllowCookies)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.BasicHttpContextBindingRequiresAllowCookie, this.Namespace, this.Name));
}
}
[DefaultValue(ContextBindingElement.DefaultContextManagementEnabled)]
public bool ContextManagementEnabled
{
get
{
return this.contextManagementEnabled;
}
set
{
this.contextManagementEnabled = value;
}
}
public override BindingElementCollection CreateBindingElements()
{
if (!this.AllowCookies)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BasicHttpContextBindingRequiresAllowCookie, this.Namespace, this.Name)));
}
BindingElementCollection result;
try
{
// Passing AllowCookies=false to HttpTransportBinding means we don't want transport layer to manage
// cookie containers. We are going to do this at the context channel level, because we need channel
// level isolation as opposed to channel factory level isolation.
this.AllowCookies = false;
result = base.CreateBindingElements();
}
finally
{
this.AllowCookies = true;
}
result.Insert(0, new ContextBindingElement(ProtectionLevel.None, ContextExchangeMechanism.HttpCookie, null, this.ContextManagementEnabled));
return result;
}
}
}