WebService.Context 屬性

定義

取得目前要求的 ASP.NET HttpContext 將 HTTP 伺服器使用的所有 HTTP 特定內容封裝,以便處理 Web 要求。

public:
 property System::Web::HttpContext ^ Context { System::Web::HttpContext ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.HttpContext Context { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Context : System.Web.HttpContext
Public ReadOnly Property Context As HttpContext

屬性值

HttpContext

目前要求的 ASP.NET HttpContext

屬性

例外狀況

Contextnull

範例

下列範例會 Context 使用 屬性來取得伺服器上的要求時間。

<%@ WebService Language="C#" Class="Util" %>
 
 using System;
 using System.Web.Services;
 
 public class Util: WebService {
   [ WebMethod(Description="Returns the time as stored on the Server",
   EnableSession=false)]
   public string Time() {
      return Context.Timestamp.TimeOfDay.ToString();
   }
 }
<%@ WebService Language="VB" Class="Util" %>
 
Imports System
Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    <WebMethod(Description := "Returns the time as stored on the Server", _
        EnableSession := False)> _
    Public Function Time() As String
        
        Return Context.Timestamp.TimeOfDay.ToString()
    End Function
End Class

備註

已將 或 SoapDocumentMethodAttribute 屬性套用至的 XML Web 服務方法,且 OneWay 屬性設為 true ,則無法使用靜態 Current 屬性存取它們 HttpContextSoapRpcMethodAttribute 若要存取 HttpContext ,請從 WebService 衍生實作 XML Web 服務方法的 類別,並存取 Context 屬性。

適用於

另請參閱