登入驗證通過後呼叫 `Response.Redirect("indexp.aspx")`,瀏覽器僅閃爍一次並停留在登入頁,不會實際導向目標頁面。程式碼邏輯如下:
if (pn.IsExit()) {
Session["PName"] = UName.Text.Trim();
Session["PWD"] = PWD.Text.Trim();
if (Person.Checked) Response.Redirect("indexp.aspx");
if (Company.Checked) Response.Redirect("indexc.aspx");
} else {
Response.Write("<script>alert('用戶名或密碼錯誤')</script>");
return;
}
Response.Redirect("indexp.aspx");
Response.End(); // 確保執行緒中止
Response.Redirect("indexp.aspx", false); // false = 不呼叫 End()
Context.ApplicationInstance.CompleteRequest(); // 優雅結束管線
// 伺服器端註冊腳本
ScriptManager.RegisterStartupScript(this, GetType(), "redirect",
"window.location='indexp.aspx';", true);
try {
if (pn.IsExit()) {
// ... Session 設定
Response.Redirect("indexp.aspx", false);
Context.ApplicationInstance.CompleteRequest();
}
} catch (ThreadAbortException) {
// 正常中止,不處理
throw; // 重新拋出
} catch (Exception ex) {
// 記錄錯誤
}
| 檢查項目 | 說明 |
|---|---|
| 瀏覽器開發者工具 Network 分頁 | 確認是否有 302 回應與 Location 標頭 |
| Fiddler 抓包 | 驗證伺服器實際回傳內容 |
| 檢查 Global.asax Application_Error | 是否攔截 ThreadAbortException |
| UpdatePanel 模式 | 改用 PostBackTrigger 或方案三 |