Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

am redirecting to login page if the session expires.
its working fine.

But i need a popup message that ur session has expired. IF i click ok on this popup message it must redirect to login page. otherwise it must stay of old page itself

This is my code

C#
protected void Page_Load(object sender, EventArgs e)
   {

C#
string ToRedirectURL = "Login.aspx";
       Response.AppendHeader("REFRESH", "60;URL=" + ToRedirectURL);


}


I think this popup script must be added there.

ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Sorry, your session timed out. Click OK to redirect to Login page, Cancel to stay of same page');document.location.href="/KB/answers/Login.aspx";", true);


Please can you help me.

Thanks.
Posted

Add this script in your page:-

C#
function SessionExpire()
{
    var answer = confirm("Sorry, your session timed out. Click OK to redirect to Login page, Cancel to stay of same page")
    if (answer){
        window.location.href="./Login.aspx";
        return  true;
    }
    else{
        return false;
    }
}


and call from code behind:-
ScriptManager.RegisterStartupScript(this, GetType(), "SessionMsg", "SessionExpire();", true);
 
Share this answer
 
write before redirecting to login page

Responce.Write("<script>alert('session expired')</script>");
Responce.Redirect("login.aspx");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900