0

Whats wrong in this?

strFname = this.Session["FileName"].ToString();

while i defined it as

Session["FileName"] = strFname;

Its giving object reference error.

Christian.K
  • 47,778
  • 10
  • 99
  • 143
Mimanshu
  • 173
  • 1
  • 2
  • 14

2 Answers2

3

Session can be transient. It may well disappear, or you might be in a new session that has never assigned anything to that key. Assume the worst - in fact, all you need is:

strFname = (string)Session["FileName"];
if(strFname != null) {
    // ...
}
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
0

There are ways you can keep sessions alive forever as long as you do not close the window. In the page you wish to keep sessions alive, add this to the .aspx page somewhere on the bottom, just before

<!-- Keep all session variables alive -->
<iframe id="Defib" src="Defibrillator.aspx" runat="server" frameborder="0" height="0" width="0"></iframe>

Now you'll have to make a new page. Call it Defibrillator.aspx This isn't my idea, but I forgot the author's name.

Defibrillator.aspx

<body></body>

Defibrillator.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    Response.AddHeader("Refresh", Convert.ToString((Session.Timeout * 60) - 10));
}
Lukas
  • 2,885
  • 2
  • 29
  • 31