AspNetCompatibilityRequirementsAttribute.RequirementsMode Property

Definition

Gets or sets the level of ASP.NET compatibility required by the service.

C#
public System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode RequirementsMode { get; set; }

Property Value

The AspNetCompatibilityRequirementsMode that indicates the services required degree of ASP.NET compatibility. The default value is Allowed.

Exceptions

The value is not a valid one for the AspNetCompatibilityRequirementsModeenum.

Examples

C#
[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;
    }
}

Remarks

Use the RequirementsMode property to set the hosting mode in code. This can also be done by setting an application-level configuration flag aspNetCompatibilityEnabled. For more information, see <serviceHostingEnvironment>.

At runtime, applications can detect whether ASP.NET compatibility mode is enabled by checking the value of the static property AspNetCompatibilityEnabled.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1