例外が発生したときに例外を表示するエラーメッセージページを作成しようとしていますが、エラーメッセージページに戻るボタンがあり、例外が発生しました。エラーメッセージを処理する方法:このコンテキストではセッション状態は使用できません
エラーページをリダイレクトするためのコードです。
protected void btnAssign_Click(object sender, EventArgs e)
{
try
{
SqlDataSource3.Insert();
}
catch (Exception ex)
{
Session["Exception"] = ex;
Response.Redirect("~/ErrorMessage.aspx", false);
}
}
ここに私のGlobal.asaxファイルのコード
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception ex = Server.GetLastError().InnerException;
Session["Exception"] = ex;
Response.Redirect("~/ErrorMessage.aspx");
}
ここでは、ErrorMessageのページのコードです。私はアサインボタンをクリックすると
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Exception ex = (Exception)Session["Exception"];
Session.Remove("Exception");
Literal1.Text = "<p style='color:blue'><b>An unrecoverable error has occurred:</b></p><br /><p style='color:red'>" + ex.Message + "</p>";
}
}
protected void btnReturn_Click(object sender, EventArgs e)
{
Response.Redirect("~/IncidentAssignment.aspx");
}
、それはErrorMessageのページを開き、例外を表示するが、私は戻るボタンをクリックすると、プログラムがクラッシュして、ファイルをGlobal.asaxのために指摘してセッション状態が、この中では使用できませんと言います文脈は、吹き飛びに示されている。
なぜセッション["例外"]がNullであるのか分かりません。もし誰かが私の質問に答えてくれたら大変感謝しています。ありがとう。
、ええが。できます。どうもありがとうございます。 – mrqyue