How can I stop code for a few seconds and then continue?
I have a page in a navbar
that only admins can enter. If you're not an admin, I want to have an alert of
You must be an admin to enter
And then the user will be Redirected to the home page. The code:
if (Session["user"] == null)
{
Response.Write("<script>alert('You must be an admin to get into this page')</script>");
System.Threading.Thread.Sleep(5000);
Response.Redirect("index.aspx");
}
But whats happening is when I press the page in the navbar
it waits five seconds and redirects me but never alerts me anything. Why is this happening?
You can use Response.AddHeader
like this:
if (Session["user"] == null)
{
Response.Write("<script>alert('You must be an admin to get into this page')</script>");
Response.AddHeader("REFRESH", "5;URL=index.aspx");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.