共用方式為


AspNetCompatibilityRequirementsAttribute.RequirementsMode 屬性

定義

取得或設定服務所需的 ASP.NET 相容性層級。

public:
 property System::ServiceModel::Activation::AspNetCompatibilityRequirementsMode RequirementsMode { System::ServiceModel::Activation::AspNetCompatibilityRequirementsMode get(); void set(System::ServiceModel::Activation::AspNetCompatibilityRequirementsMode value); };
public System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode RequirementsMode { get; set; }
member this.RequirementsMode : System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode with get, set
Public Property RequirementsMode As AspNetCompatibilityRequirementsMode

屬性值

AspNetCompatibilityRequirementsMode 表示 ASP.NET 相容性所需的服務程度。 預設值是 Allowed

例外狀況

該值不是 AspNetCompatibilityRequirementsModeenum 的其中一個有效值。

範例

[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;
    }
}
    <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)> _
    Public Class CalculatorService
        Implements ICalculatorSession

        Property Result() As Double
            ' Store result in AspNet Session.
            Get
                If (HttpContext.Current.Session("Result") Is Nothing) Then
                    Return 0D
                End If
                Return HttpContext.Current.Session("Result")
            End Get
            Set(ByVal value As Double)
                HttpContext.Current.Session("Result") = value
            End Set
        End Property

        Public Sub Clear() _
 Implements ICalculatorSession.Clear
            Result = 0D
        End Sub

        Public Sub AddTo(ByVal n As Double) _
Implements ICalculatorSession.AddTo
            Result += n
        End Sub

        Public Sub SubtractFrom(ByVal n As Double) _
Implements ICalculatorSession.SubtractFrom

            Result -= n
        End Sub

        Public Sub MultiplyBy(ByVal n As Double) _
Implements ICalculatorSession.MultiplyBy

            Result *= n
        End Sub

        Public Sub DivideBy(ByVal n As Double) _
Implements ICalculatorSession.DivideBy

            Result /= n
        End Sub

        Public Function Equal() As Double _
Implements ICalculatorSession.Equal

            Return Result
        End Function
    End Class

備註

您可以使用 RequirementsMode 屬性以程式碼來設定裝載模式。 這可以藉由設定應用程式層級的組態旗標 aspNetCompatibilityEnabled 來完成。 如需詳細資訊,請參閱< serviceHostingEnvironment >

在執行時間,應用程式可以檢查靜態屬性 AspNetCompatibilityEnabled 的值,來偵測是否啟用 ASP.NET 相容性模式。

適用於