Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2008, 01:41 PM
Authorized User
 
Join Date: May 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Web App Error on Logout

I keep getting an error in the event log when a user logs out in the session_end. The specific error code is:

Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.

The referenced lines starts this sequence. Anybody help me out? Many thanks.

If System.Web.HttpContext.Current.User IsNot Nothing Then
 If HttpContext.Current.User.Identity.IsAuthenticated Then
 System.Web.Security.FormsAuthentication.SignOut()
 System.Web.HttpContext.Current.User = Nothing
  End If
 End If
Session.Abandon()
Session.Timeout = 0
Response.Cookies.Clear()
Response.Redirect("calendar/default.aspx")



 
Old March 24th, 2008, 11:05 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The session end event in the global does not fire on a request context. Consider that if a user is making a request, then their session cannot be ending. So basically, you can not execute any code that will doing anything with HttpContext or Request/Response. You can only work with the information of the session that is ending.

It appears that you are attempting to "push" the client back to a page when their session ends. You can't do that from the server. You need to use client-side code to handle a session timeout scenario.

-Peter
peterlanoie.blog
 
Old March 25th, 2008, 08:06 AM
Authorized User
 
Join Date: May 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

Thank you for your reply. So, if I'm using forms authentication, and a person clicks a button to "log out", how would one handle that in client-side vs. server-side code? Do you have a link to an example?

Thanks so much,
Janet
 
Old March 25th, 2008, 10:40 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well, that's a bit of a different story.

If a user is explicitly logging out, then just do what you need during the code that logs them out. There isn't any need to put code in the session_end handler. (I am not even convinced that that method runs when a user logs out. Yes, they are logging out, but their session persists.)

Usually you would use session_end to execute cleanup code when a user session that ends after a period of user inactivity.

-Peter
peterlanoie.blog
 
Old March 25th, 2008, 12:30 PM
Authorized User
 
Join Date: May 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,
Thanks soooo much for your explanation. It clears things up considerably. I think I was going nuts at the time to prevent a back-button return to a page after logout - much of this stuff was trying everything at that point to get something to work.

Removed the code from session_end and everything works lovely. (Even the back-button non-return, which was really probably handled by the System.Web.Security.FormsAuthentication.SignOut() and no-cache paramters and had nothing to do with this.)

Really appreciate your time...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Interface between web app and win app alienaheart ASP.NET 2.0 Professional 4 August 4th, 2009 09:29 AM
how to implement logout for web apllication? divekar.vishal ASP.NET 2.0 Basics 3 June 6th, 2008 08:34 AM
Convert a VB.Net app to a web app? furjaw VB.NET 3 September 24th, 2007 12:27 PM
Permissions for Web app. files on Web server Jan_Ma Classic ASP Basics 0 June 28th, 2003 02:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.