[ASP.NET] ashx(泛型處理常式)中存取Session(工作階段變數)
原本的ashx
Imports System <%@ WebHandler Language="VB" Class="Handler" %> Imports System Imports System.Web Public Class Handler : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest context.Response.ContentType = "text/plain" context.Response.Write("Hello World") End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class
修改後的ashx
<%@ WebHandler Language="VB" Class="Handler" %> Imports System Imports System.Web Public Class Handler : Implements IHttpHandler, System.Web.SessionState.IRequiresSessionState Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest context.Response.ContentType = "text/plain" context.Response.Write("Hello World") If HttpContext.Current.Session.Item("SessionName") Is Nothing Then context.Response.Write("You Can Do Something.") End If End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class主要是加上System.Web.SessionState.IRequiresSessionSta 這句即可讀取
留言
張貼留言