2

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

1 に答える 1

0

あなたのコードのコメントを読むことからcontext.Session["StackOverflow"]、値は得られますが得られないと解釈し["PDFFileName"]ますか? あれは正しいですか?セッション値を割り当てるページと、セッション値を使用してデバッガーを実行するハンドラーにブレークポイントを配置します。

キーのスペルを間違えたのではないでしょうか?キーは大文字と小文字が区別されることに注意してください。

于 2013-01-18T09:18:57.513 に答える