Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:38:19+00:00 2026-06-12T07:38:19+00:00

I have setup an asp.net login control (the provided control from asp.net configuration) and

  • 0

I have setup an asp.net login control (the provided control from asp.net configuration) and it’s working fine.

I have added code to the web.config, so that after 3 min, it automatically logs out the user.

<authentication mode="Forms">
  <!-- Autologout after xxx min. to login.aspx -->
  <forms loginUrl="~/login.aspx" defaultUrl="~/login.aspx" slidingExpiration="true" timeout="3"/>
</authentication>

If using that code, then I get the autologout and if clicking on a link after 3 min then I get to the login page.

How does this work? Is it 3 min from login or is it after 3 min of inactivity !?

Also, can I add a label on my login page and then it will tell the user why he/she is redirected to the login page, if YES how ?

And lastly: how can i get it to redirect the user to the login page after 3 min. so it’s not after 3 min. and then when the user clicks a link, but so it’s after 3 min, refresh (if inactivity) and then automatically jump to the login page and show my label with text, explaining why he/she is not logged in !??

……………………………………………………………………………………………………………………………………………………….

I cant get it to work if we look at the no. 2 solution.

On my main page (code_behind) i have this in page_load Session(“logintime”) = DateTime.Now.ToString()
with a response write i get this on main page 01-10-2012 18:30:42, now its 18:37:25 and it haven’t redirect yet, and i haven’t made activity in the prowser window at all.

My code for the main page is.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="_default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var count = 30000
var timeLoggedIn = new Date('<%=Session("logintime")%>')
var timeLogOut = new Date('<%=Session("logoutTime") %>');

setTimeout(LoggedInCheck(), 30000);

function LoggedInCheck() {
    var now = new Date();
    var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
    if (now_utc > timeLogOut) {
        window.location = "http://www.google.dk";
    }
}

function countDown() {
    if (count <= 0) {
       // window.location = redirect;
    } else {
        count--;
        document.getElementById("timer").innerHTML = "This page will redirect in " + count + " seconds."
        setTimeout("countDown()", 1000)
    }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="timer">  
<script>
countDown();
</script>  
</span> 
</div>
</form>
</body>
</html>

Code_behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        Session("logintime") = DateTime.Now.ToUniversalTime().ToString("MM/dd/yyyy hh:mm:ss")
        Session("logoutTime") = DateTime.Now.ToUniversalTime().AddMinutes(3).ToString("MM/dd/yyyy hh:mm:ss")

        Response.Write("time now: " & Session("logintime"))
        Response.Write("<br />")
        Response.Write("reload at time: " & Session("logoutTime"))
    End If

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:38:20+00:00Added an answer on June 12, 2026 at 7:38 am

    This is the solution.

    In web.config add.

    <sessionState timeout="3"></sessionState> 
    

    remember its working in min.

    On the page u need to test for the autologout use this in code_behind, to start the javascript.

    Partial Class _default
    Inherits System.Web.UI.Page
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        If Not IsPostBack Then
            Page.ClientScript.RegisterStartupScript(Me.[GetType](), "onLoad", "DisplaySessionTimeout()", True)
            Response.Write(Session.Timeout)
        End If
    
    End Sub
    
    End Class
    

    U dont need the response.write its just for testing that it get the right session.timeout from web.config in min.

    On ur main page use this code, (u dont need the counter her, its just for testing so u know when its redirecting u)

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script type="text/javascript">
        var sessionTimeout = "<%= Session.Timeout %>";
        var count = 60 * sessionTimeout
        function DisplaySessionTimeout() {
            setTimeout("location.href='http://www.google.com';", 60000 * sessionTimeout);
        }
    
        function countDown() {
            count--;
            document.getElementById("timer").innerHTML = "This page will redirect in " + count + " seconds."
            setTimeout("countDown()", 1000)
        }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <span id="timer">  
    <script>
    countDown();
    </script>  
    </span> 
    </div>
    </form>
    </body>
    </html>
    

    Here its taking the session.timeout and * it with 60000 mili. sec. so it after 3 min. will redirect to the login page or in this case google.

    I havent got the time to test it with a gridview to see if its reset the counter, when the session.timeout is reset bc of activity, so u need to test that, but here is a working code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few users setup in the web.config of an asp.net site to
ISS and ASP.NET. In my setup I have a web application that must be
I have my asp.net web server setup to use windows authentication. It is authenticating
Using the ASP.NET Web-Api, I have the following POST setup in my controller. When
I have asp.net web site in which user can login and also do logout
I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code
we have asp.net web application and we need to support automatic login using domain
Curious whether folks have setup 2 way transactional replication on the tables ASP.NET uses
In my ASP.NET MVC application, I have the following setup: <runtime> <assemblyBinding xmlns=urn:schemas-microsoft-com:asm.v1> <probing
I have my asp.net sub-master page setup like this: <asp:Content ID=MainContent runat=server ContentPlaceHolderID=mainContent> <!doctype

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.