VB.NET – End user session

To end user session and disable user from using a back button to go back to secure page, you need two pages i simply named killsession.aspx and logout.aspx. I will explain both pages with code behind and markup code.

killsession.aspx

killsession.aspx (markup code)


< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div>
    </form>
</body>
</html>

killsession.aspx.vb (code behind)


Partial Class Close_Session
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
                          Handles Me.Load
      Session.Clear()
      Session.Abandon()
      Session.Remove("Name")

      Response.Redirect("logout.aspx")

    End Sub
End Class

logout.aspx

logout.aspx (markup code)

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
    <script language="javascript">
    //disable user from going back //
        function doLogout() {
            history.go(+1)
        }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>

logout.aspx.vb (code behind)

Partial Class logout
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
                       Handles Me.Load
       'fire-up java code from a markup page
        If (Not ClientScript.IsStartupScriptRegistered("doLogout")) Then
            Page.ClientScript.RegisterStartupScript _
            (Me.GetType(), "history", "doLogout();", True)
        End If
        'redirect user to a page of your choice
         Response.Redirect("default.aspx")  
    End Sub
End Class

Related posts:
Disable Back Button

VB.NET – passing string value from code behind to markup on the page

Solution 1

Protected doit As String = "Hello" (in .vb file)

< %=Me.doit%> (inside the markup)

Solution 2

'automatic properties
Protected Property doit2 As String = "Hello" (in .vb file)

< %=doit2%> (inside the markup)

'no automatic properties Private _doit3 As String (in .vb file) Protected Property doit3 As String Get Return _doit3 End Get Set(value As String) _doit3 = value End Set End Property < %=doit3%> (inside the markup)
Solution 3

Public doit4 As String = "Hello" (in .vb file)

< %=doit4%> (inside the markup)

Error – The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine.

Applies to: Microsoft Access Database Engine 2010 Redistributable

This download will install a set of components that can be used to facilitate transfer of data between 2010 Microsoft Office System files and non-Microsoft Office applications.

Overview

This download will install a set of components that facilitate the transfer of data between existing Microsoft Office files such as Microsoft Office Access 2010 (*.mdb and *.accdb) files and Microsoft Office Excel 2010 (*.xls, *.xlsx, and *.xlsb) files to other data sources such as Microsoft SQL Server. Connectivity to existing text files is also supported. ODBC and OLEDB drivers are installed for application developers to use in developing their applications with connectivity to Office file formats.

Download from Microsoft website.