Request to a handler(.ashx) from a Page(.aspx)

G

Guest

I am trying to use .ashx files to handle dynamic image requests. The aspx page needs to pass the data to the ashx file. It was decided to not use the query string. Instead we hoped we could use the Session or the Context cache.

e.g. (in the aspx page)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Context.Current.Items.Add("Msg", "NAM2")
Me.Session.Add("Msg", "NAM2")
Me.Session.Timeout = 15
Me.Image1.ImageUrl = "test.ashx" 'the image request to the ashx file
End Sub


however, when we try to take the data from the session or context cache in the ashx handler, we observe that the Session and context are not the same for the aspx and the ashx file.
e.g. (in the ashx file)

Public Overridable Overloads Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim bmp As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim mybrush As New Drawing2D.LinearGradientBrush(New RectangleF(0, 0, 100, 100), Color.Red, Color.Yellow, Drawing2D.LinearGradientMode.Horizontal)
Try
context.Response.ContentType = "image/gif"
g.FillRectangle(Brushes.Blue, New RectangleF(0, 0, 100, 100))

Try
g.DrawString(CStr(context.Session.Item("Msg")), New Font("Times New Roman", 24), mybrush, 5, 25)

Catch e As Exception
g.DrawString("Err", New Font("Times New Roman", 24), mybrush, 5, 25)
End Try
bmp.Save(context.Response.OutputStream, Imaging.ImageFormat.Gif)
Catch
Finally
g.Dispose()
bmp.Dispose()
End Try
End Sub

what is the problem?Is session and Context cache shared between an aspx page and an ashx handler? advise would be appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top