許可されていないユーザーがページにアクセスするのを制限し、そのユーザーを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
ですか?
また、これら 2 つのアプローチをPage_Load
of で試しましたがDefault.aspx
、どちらも機能しませんでした。特定のセッションバリアブルが設定されている場合、アラートを表示します。
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.');");
}