WebService.Context 属性

获取当前请求的 ASP.NET HttpContext,它封装了由 HTTP 服务器用来处理 Web 请求的所有 HTTP 特定的上下文。

**命名空间:**System.Web.Services
**程序集:**System.Web.Services(在 system.web.services.dll 中)

语法

声明
Public ReadOnly Property Context As HttpContext
用法
Dim instance As WebService
Dim value As HttpContext

value = instance.Context
public HttpContext Context { get; }
public:
property HttpContext^ Context {
    HttpContext^ get ();
}
/** @property */
public HttpContext get_Context ()
public function get Context () : HttpContext

属性值

当前请求的 ASP.NET HttpContext

异常

异常类型 条件

Exception

Context 为 空引用(在 Visual Basic 中为 Nothing)。

备注

应用 SoapRpcMethodAttributeSoapDocumentMethodAttribute 属性,且 OneWay 属性设置为 true 的 XML Web services 方法不能使用静态 Current 属性访问其 HttpContext。若要访问 HttpContext,请从 WebService 派生实现 XML Web services 方法的类,并访问 Context 属性。

示例

下例使用 Context 属性在服务器上获取请求的时间。

<%@ 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
 
<%@ 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();
   }
 }
 

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

WebService 类
WebService 成员
System.Web.Services 命名空间
HttpContext