7

目标:我有一个缩略图作为内存中的字节数组。一旦用户上传了他们的图像,我想在将其写入数据库之前将其显示在 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
4

2 回答 2

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
于 2009-08-06T19:04:08.783 回答
1

索拉林是对的。我必须实现 IRequiresSessionState。我没有意识到的是,我不得不将变量称为

context.Session("oUser")

代替

Session("oUser")
于 2009-08-06T19:36:16.610 回答