0

Whats wrong in this?

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

while i defined it as

Session["FileName"] = strFname;

Its giving object reference error.

0

2 Answers 2

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) {
    // ...
}
Sign up to request clarification or add additional context in comments.

Comments

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));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.