locked
Session shows only after refresh RRS feed

  • Question

  • User-557124927 posted
    Hi Guys,
    I am trying to implement an httphandler in an application. the handler module assigns one of the values to a session variable which I want to use in an aspx page_load event
    this is my code here
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Context.Session("datasession") Is Nothing And IsPostBack = False Then
                Response.Write("Session is available!")
                Else
                Response.Write("Session is not available!")
     End If
    End Sub
    every time the aspx page loads the output is Session is not available! unless I hit the refresh button or F5 in IE then the output would show as Session is available!
    am I missing something??

    TIA
    Saturday, February 11, 2006 1:59 AM

All replies

  • User-1029435529 posted

    In reading your post, it sounds a little like you are confusing an HttpHandler and an HttpModule. That is, while you opened by saying that you are implementing an HttpHandler, the rest of your post suggests it is an HttpModule.

    Perhaps you can show the code for the class in which your code "assigns one of the values to a session variable"?
     

    Saturday, February 11, 2006 2:45 AM
  • User-557124927 posted
    Ok what i am trying to do is create an image from an ashx to perform verification on a form. the image is created fine and random string are created and displayed fine. I have the random string assigned to a session variable.
    <%@ WebHandler Language="VB" Class="RegisterImageHandler" %>
    Imports System
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Text
    Imports System.Web
    Imports System.Web.SessionState
    Public Class RegisterImageHandler
        Implements IHttpHandler
        Implements IRequiresSessionState

     Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    'code to create the image and random string
    context.Session("datasession") = strRandomString.ToString()
            objBitmap.Save(context.Response.OutputStream, ImageFormat.Gif)
           context.Response.End()
     End Sub

        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return True
            End Get
        End Property
       
    End Class
    I hope that explains it enough.
    Thanks


    Saturday, February 11, 2006 4:43 AM
  • User-1372641848 posted

    You will have to change your logic. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    Session value won't be available to page because handler (image) is called only after your page completes execution and goes to client. Instead of creating random string in handler create that into page put into session and then use that in handler.

    Saturday, February 11, 2006 9:20 AM
  • User-557124927 posted
    Thanks, That explains why the previous random shows after the page is refreshed
    I am just going to scrap the .ashx completely and build the image in a class by itself.

    Thank you

    Saturday, February 11, 2006 3:49 PM