Redirecting User to Login Page After session Timeouts

xiaoxiao2021-03-06  89

Redirecting User to Login Page After session Timeouts

In most of the applications you might come across the situation where you need to redirect the user to login page after session timeouts. It is simple, if you want to redirect user to login page when the user submits the page after session timeout. You got the control in server, you can check for session timeout. If that is true, then you can redirect the user to any page you want. If you implemented authentication like Forms authentication or Passport authentication in your applications. Then this is done automatically when the User resubmits the page after session timeouts.

But the requirement is such that you want to redirect the user immediately after timeout to login page before the user submits the page. In this article, I am going to explain how we can achieve this in ASP.NET.Before we see how to redirect . This is the page name.

Refreshing Any Page After Certain Interval

For refreshing any page after certain interval, you need to use client side script only You cant do this in server side, The reason being that the page has been served to the client, end of request The web is stateless;.. Until the user Comes back and initiates another request the server can't do anything. so we need to do this refreshing activity from client side only. There four

Using window.Settimeout Method 2. Using meta tag - refresh.

Using window.settimeout method:

DHTML Window object has a method called "setTimeout" which evaluates an expression after a specified number of milliseconds has elapsed. With the help of this method, you can run the client side script window.location.href = "somepage" to redirect page in the current window. SetTimeout accepts three parameters.vCodeRequired. Variant that specifies the function pointer or string indicates the code to be executed when the specified interval has elapsed.iMilliSecondsRequired. Integer that specifies the number of milliseconds.sLanguageOptional. String that specifies one that of The Following Values:

JScriptLanguage IS JScript.vbscriptlanguage is Vbscript.javascriptLanguage IS JavaScript.

You need to call this method in body load and start the timer (by calling setTimeout method). This timer will elapse depending upon the second parameter for this method. When it is elapsed, it will fire the script which is given as first parameter. .

.

2. In The Code Behind, Declare This Element as HTMLGENERICCONTROL LIKE THIS.

Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl 3. Finally add the following code in your page_load event handler, this will add the client side handler for body tag. Body.Attributes.Add ( "onLoad", "window. Settimeout ("" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, . in some lower end browsers So you need to go for other method ie by using Meta Tags Using Meta Tag -. Refresh Another way for refreshing the page after certain interval is by using meta tag -. Refresh This tag specifies a delay in seconds before the browser automatically reloads the document Optionally, specifies an alternative URL to load Example.. In ASP .NET, You CAN add headers in code behind using this method. Response.Appendheader ("refresh", "10; URL = .ASPX ")

转载请注明原文地址:https://www.9cbs.com/read-125143.html

New Post(0)