【发布时间】:2018-07-29 10:36:48
【问题描述】:
我找到了很多例子,但我不知道为什么这些对我不起作用。这些我都试过了,但是没用。
- How to show Javascript Alert message before redirecting to same page in VB.NET?
- Javascript Alert before redirecting in ASP.NET
- Asp.net Webform Display Alert and redirect
我也尝试了以下方法:
String message = "Session Expired! Log In Again.";
ClientScript.RegisterStartupScript(
this.GetType(),
Guid.NewGuid().ToString(),
string.Format("alert('{0}');window.location.href = 'default.aspx'",
message.Replace("'", @"\'").Replace("\n", "\\n").Replace("\r", "\\r")),
true);
和
ScriptManager.RegisterStartupScript(
this,
this.GetType(),
"redirect",
"alert('Session Expired! Log In Again.');
window.location='" + Request.ApplicationPath + "Account/login.aspx';",
true);
和
Response.Write("
<script language='javascript'>
window.alert('Session Expired');
window.location='~/Account/Login.aspx';
</script>");
但所有这些都不会重定向到仅显示警报消息的登录页面。
【问题讨论】:
-
谁能告诉我为什么这一行显示警报消息但没有重定向到登录页面。
ScriptManager.RegisterStartupScript( this, this.GetType(), "redirect", "alert('Session Expired! Log In Again.'); window.location='~" + Request.ApplicationPath + "Account/login.aspx';", true);
标签: javascript c# asp.net