Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

automatically Log off User Page

$
0
0

Hi,

I'm using VS2010

i'm looking for a solution how to automatically log of users after 3 mins , here is my code but somehow 

it won't work , can you help me out ? thanks

See my Code:

//UserPage.aspx

<script type="text/javascript">
var sessionTimeout = "<%= Session.Timeout %>";
function DisplaySessionTimeout() {
//assigning minutes left to session timeout to Label
document.getElementById("<%= lblSessionTime.ClientID %>").innerText = sessionTimeout;
sessionTimeout = sessionTimeout - 1;

//if session is not less than 0
if (sessionTimeout >= 0)
//call the function again after 1 minute delay
window.setTimeout("DisplaySessionTimeout()", 60000);
else {
//show message box
alert("Your current Session is over.");
$.timeoutDialog({ timeout: 0.25, countdown: 15, logout_redirect_url: 'LogIn.aspx'});
}
}
</script>

//UserPage.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text += Session["Name"].ToString();
if (!IsPostBack)
{
//set DisplaySessionTimeout() as the startup script of this page
Page.ClientScript.RegisterStartupScript(this.GetType(), "onLoad", "DisplaySessionTimeout()", true);
// Page.ClientScript.RegisterStartupScript(Me.[GetType](), "onLoad", "Session.Abandon()", True)
Page.ClientScript.RegisterStartupScript(this.GetType(), "onLoad", "FormsAuthentication.SignOut()", true);
}
}

//web.config

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<sessionState timeout="3"></sessionState>
</system.web>
</configuration>

After I LogIn it successfully go to User page. But the problem is after 3 miniutes it display the Alert box only. It doesn't redirect(goto) to LogIn page.

Please Help me.


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>