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

Discussion in 'ASP .Net' started by =?Utf-8?B?Sko=?=, Jun 30, 2004.

  1. 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!
    =?Utf-8?B?Sko=?=, Jun 30, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bart Adriaanse

    ASHX handler using codebehind ?

    Bart Adriaanse, Dec 8, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    5,057
  2. Jan Kucera

    Session is null in ashx handler

    Jan Kucera, Aug 24, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    12,093
    Jan Kucera
    Aug 25, 2006
  3. Carl Gilbert
    Replies:
    0
    Views:
    448
    Carl Gilbert
    Oct 4, 2006
  4. Replies:
    0
    Views:
    340
  5. JJ
    Replies:
    3
    Views:
    798
    Steven Cheng[MSFT]
    Nov 21, 2007
Loading...

Share This Page