WebService.Context プロパティ

定義

現在の要求に対する ASP.NET HttpContext を取得します。これには、HTTP サーバーが Web 要求を処理するために使用するすべての HTTP 固有のコンテキストがカプセル化されています。

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

注釈

プロパティが設定trueされた SoapRpcMethodAttribute XML Web サービス メソッドまたはSoapDocumentMethodAttribute属性が適用されている OneWay XML Web サービス メソッドは、静的Currentプロパティを使用してそれらにHttpContextアクセスできません。 にHttpContextアクセスするには、XML Web サービス メソッドを実装するクラスを派生させ、プロパティにWebServiceContextアクセスします。

適用対象

こちらもご覧ください