目标:我在内存中有一个缩略图作为字节数组。一旦用户上传了他们的图像,我想在将其写入数据库之前将其显示在httphandler中。我已经使用此代码成功读取并显示数据库。但现在我想从会话中显示它:
Public Sub ProcessRequest(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
Dim oPhotoMgt As New PhotoMgt
Dim intPhotoID As Int32 = context.Request.QueryString("id")
Dim oPhoto As New Photo
oPhoto = oPhotoMgt.GetPhotoByID(intPhotoID)
context.Response.ContentType = "image/jpeg"
context.Response.BinaryWrite(oPhoto.Bytes.ToArray())
End Sub
答案 0 :(得分:15)
您应该使用IRequiresSessionState接口(System.Web.SessionState
命名空间)标记您的类。它没有方法或属性,因此您不必更改有关代码的任何其他内容。
签名将是:
Imports System.Web
Imports System.Web.SessionState
Public Class MyHandler
Implements IHttpHandler, IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
context.Session("foo") = "bar"
End Sub
End Class
答案 1 :(得分:1)
胸腺素是正确的。我必须实现IRequiresSessionState。我没有意识到的是,我必须将变量称为
context.Session("oUser")
而不是
Session("oUser")