Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Bromberg's Session Timeout Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SAL - 18 Dec 2007 16:22 GMT
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
Peter Bromberg [C# MVP] - 18 Dec 2007 18:29 GMT
SAL,
It worked fine when I wrote the article. Of course, you have translated in
to VB.NET so you may have a little boo-boo in there somewhere. Also, there
have been some minor changes in Session behavior since ASP.NET 2.0 came out.
I'd just set a breakpoint on the pertinent line in debug mode and test it
from another machine (not from localhost).
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Hello,
> I'm trying to implement Peter Bromberg's Session Timeout Control:
[quoted text clipped - 85 lines]
>
> SAL
SAL - 18 Dec 2007 20:34 GMT
The code works fine if I stick it in the PageError event.
The real problem is getting the OnPreRender to fire. It doesn't step into
that code at all and I have
AutoEventWireup="true"

SAL

> SAL,
> It worked fine when I wrote the article. Of course, you have translated in
[quoted text clipped - 99 lines]
>>
>> SAL

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.