1

The following code is working on IE but not on Firefox. The following code is setting session on *.ashx file.

public class Upload : IHttpHandler, IRequiresSessionState
{
    public string PATH = System.Web.HttpContext.Current.Request.MapPath("..") + @"\UploadFiles\";
    public string prefix = "ANNUAL_";
    public void ProcessRequest(HttpContext context)
    {            
        HttpPostedFile file = context.Request.Files["Filedata"];
        file.SaveAs(PATH + prefix + file.FileName);                
        HttpContext.Current.Session["filename"] = file.FileName;  
        context.Response.Write("1");
    }
}

Getting session in *.aspx file is as follows. Even though I can set value into the sessions in *ashx file, the session value is null when session arrives in the *.aspx file. How can I solve my problem? Could you please give any solution about my problem?

using System.Web.SessionState;
public partial class frmImport : System.Web.UI.Page, IReadOnlySessionState
{
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string temp = HttpContext.Current.Session["filename"].ToString();
    }
}
linnaryone
  • 21
  • 1
  • 4
  • 1
    The problem is probably on the cookie setup on web.config, you need there to be correctly set the path and the domain that set the cookie. – Aristos Sep 17 '10 at 06:32

2 Answers2

1

Put the following code in Web.Config

<configuration>
   <system.web>
<sessionState mode="InProc"  cookieless="true" />

The problem has gone !

cjk
  • 45,739
  • 9
  • 81
  • 112
linnaryone
  • 21
  • 1
  • 4
  • I hope you understand the implications, and not only did it because 'it works' :( – eglasius Sep 17 '10 at 07:21
  • adding this does url tampering with sessionID with the url... which feels not much gud.. Like http://domain/(S(jjbbqk55fc0b3w55fwtyzd55))/Default.aspx to all the pages is there any other method to get session without tampering the url. – deepu Dec 27 '10 at 06:54
-1

Here is the TRUE solution to fix this: How to access session in aspx that was modified in ashx?

It's because flash does not send the sessionid to the handler.

Community
  • 1
  • 1
Steve Stokes
  • 1,200
  • 18
  • 36