編輯

共用方式為


WebService.Context Property

Definition

Gets the ASP.NET HttpContext for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests.

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

Property Value

The ASP.NET HttpContext for the current request.

Attributes

Exceptions

Context is null.

Examples

The Example below uses the Context property to obtain the time of the request on the server.

<%@ 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

Remarks

XML Web service methods that have either the SoapRpcMethodAttribute or SoapDocumentMethodAttribute attribute applied to them with the OneWay property of set to true, do not have access to their HttpContext using the static Current property. To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.

Applies to

See also