7

What is the maximum size a session variable can hold ? I am trying to store object in session variable, if object size is under 80 KB, then working fine and if the size is greater than 80 KB then on retrieval I am getting an exception.

How can I increase the session variable size?

This behaviour is on my production server, on the development machine I can store big objects like above 500 KB etc..

I am implementing something like... http://aspalliance.com/1221_CodeSnip_Uploading_Multiple_Files_At_Once.all

Here is my code:

private static int count = 0;

protected void Upload_Click(object sender, EventArgs e)
{
    for (int loopCount = 0; loopCount < count; loopCount++)
    {
        HtmlInputFile hif = (HtmlInputFile)Session["myupload" + loopCount];
        String filePath = Server.MapPath("~/AdvImages/") + loopCount.ToString() + "_" + hif.PostedFile.FileName;
        hif.PostedFile.SaveAs(filePath);
        Session.Abandon();
    }
}
protected void btnAdd_Click1(object sender, EventArgs e)
{
    Session["myupload" + count] = FileUpload1;
    count++;
}

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • @Pina, Actually I am storing fileupload object and if the file size is greater than 80 KB, I am getting exception like "Cannot access a closed file" – Muhammad Akhtar Nov 18 '09 at 11:31
  • Which session state mode are you using? InProc? SQL? – RickNZ Nov 18 '09 at 11:31
  • Can you post your code. You said in the comments that you are doing something different if it's over 80k, so is doesn't sound like a size problem, just a problem with your code in that case. – UpTheCreek Nov 18 '09 at 11:36
  • @Sosh, Actually I am implmenting this thing http://aspalliance.com/1221_CodeSnip_Uploading_Multiple_Files_At_Once.all Multiple fileload atonce – Muhammad Akhtar Nov 18 '09 at 11:40
  • @Sosh, I am 100% sure, that there is no problem with my code, because I have check all alternative and finally I am reach that this the problem – Muhammad Akhtar Nov 18 '09 at 11:43
  • thanks for all the time, I have posted my code..Thanks – Muhammad Akhtar Nov 18 '09 at 11:48

2 Answers2

3

Try to change requestLengthDiskThreshold to this:

<system.web>
    <httpRuntime executionTimeout="90" 
                 maxRequestLength="20000" 
                 useFullyQualifiedRedirectUrl="false" 
                 requestLengthDiskThreshold="8192"/>
</system.web>
Arjun Prakash
  • 669
  • 9
  • 23
Vitaly
  • 2,567
  • 5
  • 29
  • 34
2

From what i can think of, storing files in a session variable is a bad choice! Instead you can think of putting them into a temp location and then when upload is clicked you can put the to the real storage. Later on you can clear off the temp storage.

Illuminati
  • 4,539
  • 2
  • 35
  • 55