views:

318

answers:

1

I am setting a Session variable in an HttpHandler, and then getting its value in the Page_load event of an ASPX page. I'm setting it using

    public void ProcessRequest(HttpContext context)
    {
        HttpPostedFile file = context.Request.Files["Filedata"];
        context.Session["WorkingImage"] = file.FileName;
    }

(And before someone suggests that I check the validity of file.FileName, this same problem occurs if I hard-code a test string in there.) It's working just fine in IE, but in Firefox the Session Variable is not found, getting the "Object reference not set to an instance of an object" error in the following code:

   protected void Page_Load(object sender, EventArgs e)
   {
        string loc = Session["WorkingImage"].ToString();
   }

Has anyone encountered this problem - and hopefully come up with a means for passing the session variable?

A: 

This is for an HTTPHandler? If this by some chance has something to do with Flash, and Flash is making the request, you will be very interested in reading about the Flash Cookie Bug. Basically, Flash only forwards IE cookies.

The easist fix is to call correctCookie at Application_BeginRequest in your Global.asax and put the SessionId in the querystring of the Flash request.

Public Shared Sub correctCookie()
    Try
        Dim session_cookie_name As String = "ASP.NET_SESSIONID"
        Dim session_value As String = HttpContext.Current.Request.QueryString("sid")
        If session_value IsNot Nothing Then
            UpdateCookie(session_cookie_name, session_value)
        End If
    Catch ex As Exception
    End Try
End Sub

Private Shared Sub UpdateCookie(ByVal cookie_name As String, ByVal cookie_value As String)
    Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies.[Get](cookie_name)
    If cookie Is Nothing Then
        Dim cookie1 As New HttpCookie(cookie_name, cookie_value)
        HttpContext.Current.Response.Cookies.Add(cookie1)
    Else
        cookie.Value = cookie_value
        HttpContext.Current.Request.Cookies.[Set](cookie)
    End If
End Sub
dtryan