我试图限制未经授权的用户访问Utilities.aspx页面并将他重定向到Default.aspx页面。
if (authorizedUser.ToLower() != "admin")
{
if (!ClientScript.IsClientScriptBlockRegistered("UnauthorizedUserRedirect"))
{
ClientScript.RegisterStartupScript(this.GetType(), "UnauthorizedUserRedirect", "<script>alert('Unauthorized access!\n\nYou have attempted to access a page that you are not authorized to view.')</script>", true);
Response.Redirect("Default.aspx");
}
}
但是,虽然重定向工作正常,但alert页面上没有显示。搜索这个问题告诉我 Response.Redirect 在客户端代码完全呈现之前完成了它的操作。
我怎样才能显示alert之前的Response.Redirect?
我也尝试了这两种方法,Page_Load但Default.aspx都没有奏效。如果设置了某个会话 bariable,则显示警报。
if (Session["unauth"] != null)
{
ClientScript.RegisterStartupScript(this.GetType(), "UnauthorizedUserRedirect", "alert('Unauthorized access!\n\nYou have attempted to access a page that you are not authorized to view.');", true);
}
if (Session["unauth"] != null)
{
form1.Attributes.Add("OnLoad", "javascript:alert('Unauthorized access!\n\nYou have attempted to access a page that you are not authorized to view.');");
}