Export (0) Print
Expand All

AspNetCompatibilityRequirementsMode Enumeration

Specifies whether a service runs, or can run, in a mode that is compatible with ASP.NET.

Namespace:  System.ServiceModel.Activation
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public enum AspNetCompatibilityRequirementsMode

Member nameDescription
NotAllowed services must run in an application domain with ASP.NET compatibility mode set to false.
Allowed services can run in an application domain with ASP.NET compatibility mode set to true or false.
Required services must run in an application domain with ASP.NET compatibility mode set to true.

ASP.NET compatibility mode allows services to use ASP features such as identity impersonation. It is enabled at the application level through the Web.config file and cannot be overridden by Web.config files nested in the application. When the AspNetCompatibilityRequirementsMode value is not specified for a service, it gets NotAllowed behavior by default. For more information, see serviceHostingEnvironment.

Service developers must explicitly opt-in for the ASP.NET compatibility mode when implementing the service by setting the RequirementsMode property on the AspNetCompatibilityRequirementsAttribute as shown in the following example:


[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculatorSession
{
    [OperationContract]
    void Clear();
    [OperationContract]
    void AddTo(double n);
    [OperationContract]
    void SubtractFrom(double n);
    [OperationContract]
    void MultiplyBy(double n);
    [OperationContract]
    void DivideBy(double n);
    [OperationContract]
    double Equals();
}



[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CalculatorService : ICalculatorSession
{
    double result
    {   // Store result in AspNet session.
        get
        {
            if (HttpContext.Current.Session["Result"] != null)
                return (double)HttpContext.Current.Session["Result"];
            return 0.0D;
        }
        set
        {
            HttpContext.Current.Session["Result"] = value;
        }
    }

    public void Clear()
    {

    }

    public void AddTo(double n)
    {
        result += n;
    }

    public void SubtractFrom(double n)
    {
        result -= n;
    }

    public void MultiplyBy(double n)
    {
        result *= n;
    }

    public void DivideBy(double n)
    {
        result /= n;
    }

    public double Equals()
    {
        return result;
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft