views:

173

answers:

2

Am not sure why when using IE, retrieving session values works just fine, but when using Google Chrome and Firefox, it's not returning any?

I have already included IRequiresSessionState/IReadOnlySessionState in generic handler class, but still did not work.

So my last resort was to add my session values as a query string in generic handler.

But I still want to know why and what's wrong in Chrome and Firefox? Thanks.

UPDATE: here's the way I handle my Seesion SessionManager

It works perfectly in ASPX pages and in IE, Chrome, and Firefox

but when used in my ASHX page. sample code below

<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.IO;

public class Upload : IHttpHandler, IReadOnlySessionState
{
    SessionManager sm;

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;

        sm = new SessionManager();

        try
        {
            HttpPostedFile postedFile = context.Request.Files["Filedata"];

            string uploadedas = string.Empty;
            if (context.Request.QueryString["as"] != null)
            {
                uploadedas = context.Request.QueryString["as"];
            }

            string username = sm.Username;
            string sessionid = sm.SessionID;

            //
            // MORE CODES HERE
            //

            context.Response.Write(response);
            context.Response.StatusCode = 200;
        }
        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message + "\r\n\r\n" + ex.StackTrace);
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

sm.Username and sm.SessionID returns an emptry string when Chrome and Firefox is used.. but as I said earlier, those are working perfectly in ASPX pages even in different browsers.

A: 

A session is a type of cookie. Make sure you have cookies enabled on all the browsers you are testing in.

Tom Gullen
thanks tom. Rechecking those options in Google Chrome and Firefox, saving Cookies are enabled.
Nullstr1ng
A: 

How are you calling your ashx from your page? Can you give sample code?

Do you use Flash to call the ashx? Flash has a cookie bug that always sends IE cookies to the server whichregardless of which browser you are using which makes accessing ASP.NET Session hard since it relies on a cookie.

Andreas Paulsson