2

I cannot get session value at ASHX file.
I had searched here so I can solve my problem.

But I still cannot get session value. Please let me get your suggestion.

[ASPX Design File]

...
<form id="form1" runat="server">
<div>
    <iframe runat="server" id="iframepdf" height="600" width="800" src="./PDFViewer.ashx"></iframe>
</div>
</form>
...

[ASPX Code Behind]

...
namespace WebApplication1
{
public partial class NameCard : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        Session["PDFFileName"] = @"D:\Test.pdf";
    }
}
}

As you see my code behind file,
I set some value to session object.
And then, I write below ashx file.

[ASHX Code Behind]

...
namespace WebApplication1
{
public class PDFViewer : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {   
        context.Session["StackOverflow"] = "overflowing";  // This one give me output value as "overflowing"
        if (context.Session["PDFFileName"] != null) {  // My problem is this line, It always say null value ...
            context.Response.ContentType = "Application/pdf";
            var PDFFileName = context.Session["PDFFileName"].ToString();                
            context.Response.WriteFile(PDFFileName);
            context.Response.End();
            context.Session["PDFFileName"] = string.Empty;
        }

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
}
Community
  • 1
  • 1
Frank Myat Thu
  • 4,448
  • 9
  • 67
  • 113

1 Answers1

0

From reading the comments in you code I interpret it that you get the context.Session["StackOverflow"] but not the ["PDFFileName"] value? Is that correct? Put a breakpoint in the pages where you assign the session values and in the handler where you use them and run a debugger.

Maybe you've misspelled the keys? Remember that the keys are case sensetive.

mortb
  • 9,361
  • 3
  • 26
  • 44