WebService.Context WebService.Context WebService.Context WebService.Context Property

定义

获取当前请求的 ASP.NET HttpContext,它封装了由 HTTP 服务器用来处理 Web 请求的所有 HTTP 特定的上下文。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; }
member this.Context : System.Web.HttpContext
Public ReadOnly Property Context As HttpContext

属性值

当前请求的 ASP.NET HttpContextThe ASP.NET HttpContext for the current request.

异常

ContextnullContext is null.

示例

下面的示例使用Context属性获取服务器上的请求的时间。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

注解

如果SoapRpcMethodAttribute HttpContext true应用了CurrentSoapDocumentMethodAttribute特性的 XML Web service 方法的属性设置为,则无法使用静态属性OneWay访问这些方法。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. 若要访问HttpContext, 请派生类实现 XML Web service WebService方法, 并访问Context属性。To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.

适用于

另请参阅