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