ASHX ファイルでセッション値を取得できません。ここで
検索したので、問題を解決できました。
しかし、まだセッション値を取得できません。あなたの提案を聞かせてください。
【ASPXデザインファイル】
...
<form id="form1" runat="server">
<div>
<iframe runat="server" id="iframepdf" height="600" width="800" src="./PDFViewer.ashx"></iframe>
</div>
</form>
...
[ASPXコードビハインド]
...
namespace WebApplication1
{
public partial class NameCard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["PDFFileName"] = @"D:\Test.pdf";
}
}
}
コード ビハインド ファイルを見ると、
セッション オブジェクトに値を設定しています。
そして、ashxファイルの下に書きます。
[ASHXコードビハインド]
...
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;
}
}
}
}