S
SAL
Hello,
I'm trying to implement Peter Bromberg's Session Timeout Control:
http://www.eggheadcafe.com/articles/20051228.asp
in ASP.NET 2.0 and am finding that the code never fires. I'm not sure what
I'm doing wrong here. Yes, it would be easy enough to place some of that
code in a class, or test for a particular Session variable but it would be
nice to have a control to drop on a web form and have it just work. Can
anyone tell me what I might be missing. Sorry, I'm still pretty new to
ASP.NET:
Imports System
Imports System.ComponentModel
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
<DefaultProperty("Text"), _
ToolboxData("<{0}:SessionTimeoutControl
runat=server></{0}:SessionTimeoutControl>")> _
Partial Class UserControls_SessionTimeOutControl
Inherits System.Web.UI.UserControl
' reference for this control:
' http://www.eggheadcafe.com/articles/20051228.asp
#Region "Private member variables"
Private mRedirectUrl As String
#End Region
#Region "Public Properties"
<Bindable(True), Category("Appearance"), DefaultValue("")> _
Public Property RedirectUrl() As String
Get
Return mRedirectUrl
End Get
Set(ByVal value As String)
mRedirectUrl = value
End Set
End Property
Public Overrides Property Visible() As Boolean
Get
Return False
End Get
Set(ByVal value As Boolean)
'
End Set
End Property
Public Overrides Property EnableViewState() As Boolean
Get
Return False
End Get
Set(ByVal value As Boolean)
'MyBase.EnableViewState = value
End Set
End Property
#End Region
#Region "Protected Members"
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
If HttpContext.Current Is Nothing Then
writer.Write("[ *** SessionTimeout: " + Me.ID + " *** ]")
End If
MyBase.Render(writer)
End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
MyBase.OnPreRender(e)
If Me.mRedirectUrl Is Nothing Then
Throw New InvalidOperationException("RedirectUrl Property Not
Set.")
End If
If Context.Session IsNot Nothing Then
Dim sCookieHeader As String = Page.Request.Headers("Cookie")
If (sCookieHeader IsNot Nothing) And
(sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0) Then
If Page.Request.IsAuthenticated Then
FormsAuthentication.SignOut()
End If
Page.Response.Redirect(Me.mRedirectUrl)
End If
End If
End Sub
#End Region
End Class
SAL
I'm trying to implement Peter Bromberg's Session Timeout Control:
http://www.eggheadcafe.com/articles/20051228.asp
in ASP.NET 2.0 and am finding that the code never fires. I'm not sure what
I'm doing wrong here. Yes, it would be easy enough to place some of that
code in a class, or test for a particular Session variable but it would be
nice to have a control to drop on a web form and have it just work. Can
anyone tell me what I might be missing. Sorry, I'm still pretty new to
ASP.NET:
Imports System
Imports System.ComponentModel
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
<DefaultProperty("Text"), _
ToolboxData("<{0}:SessionTimeoutControl
runat=server></{0}:SessionTimeoutControl>")> _
Partial Class UserControls_SessionTimeOutControl
Inherits System.Web.UI.UserControl
' reference for this control:
' http://www.eggheadcafe.com/articles/20051228.asp
#Region "Private member variables"
Private mRedirectUrl As String
#End Region
#Region "Public Properties"
<Bindable(True), Category("Appearance"), DefaultValue("")> _
Public Property RedirectUrl() As String
Get
Return mRedirectUrl
End Get
Set(ByVal value As String)
mRedirectUrl = value
End Set
End Property
Public Overrides Property Visible() As Boolean
Get
Return False
End Get
Set(ByVal value As Boolean)
'
End Set
End Property
Public Overrides Property EnableViewState() As Boolean
Get
Return False
End Get
Set(ByVal value As Boolean)
'MyBase.EnableViewState = value
End Set
End Property
#End Region
#Region "Protected Members"
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
If HttpContext.Current Is Nothing Then
writer.Write("[ *** SessionTimeout: " + Me.ID + " *** ]")
End If
MyBase.Render(writer)
End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
MyBase.OnPreRender(e)
If Me.mRedirectUrl Is Nothing Then
Throw New InvalidOperationException("RedirectUrl Property Not
Set.")
End If
If Context.Session IsNot Nothing Then
Dim sCookieHeader As String = Page.Request.Headers("Cookie")
If (sCookieHeader IsNot Nothing) And
(sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0) Then
If Page.Request.IsAuthenticated Then
FormsAuthentication.SignOut()
End If
Page.Response.Redirect(Me.mRedirectUrl)
End If
End If
End Sub
#End Region
End Class
SAL