Solved

Unhandled Errors in Logout page

Posted on 2011-09-23
11
322 Views
Last Modified: 2012-05-12
I have a fairly simple logout page   logout.aspx and for some reason it keeps logging an error.

The only thing I can if of is that the connection to the database has been lost and it can end the session and it tosses the error.  Any thoughts on the actual cause.  code is below.  Using IIS6 and .net framework 2.0



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class LogOut : System.Web.UI.Page
{
    public static log4net.ILog log;

    public LogOut()
    {
        log4net.Config.XmlConfigurator.Configure();
        log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Session["LoggedOut"] = true;
        Session["IsLoggedIn"] = false;
        log4net.ThreadContext.Properties["Action"] = "Logout";
        log.Info("User Logged Out");
        Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(-1);
        FormsAuthentication.SignOut();
        Session.Abandon();
        Response.Redirect("~/weblogin.aspx");
        //FormsAuthentication.RedirectToLoginPage();
    }
}
0
Comment
Question by:TimSweet220
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 36590386
Can you specify the error message and line in your code.

In the mean time, just use Session.Abandon() or Session.Clear but do not assign any Session values. (What's the point if you are going to erase them any way)
Check:
http://stackoverflow.com/questions/347377/in-asp-net-when-should-i-use-session-clear-rather-than-session-abandon
0
 
LVL 15

Accepted Solution

by:
Eyal earned 250 total points
ID: 36594322
maybe this is causing your problem

HttpContext.Current.Response.Redirect("~/weblogin.aspx",false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
0
 

Author Comment

by:TimSweet220
ID: 36595186
Eyal - If they log out I want them redirected back to the log in page.

What will your suggested code do?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 250 total points
ID: 36596279
Try:
protected void Page_Load(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("~/weblogin.aspx");
    }
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36596946
sometimes Redirect statement gives error when using it, maybe it is related to that.

can you give us the detailed error / error line ?
0
 

Author Comment

by:TimSweet220
ID: 36599676
I will attempt get that detail..issue is I can not reproduce this error in the test environment and the errors come to me in a generic report with just the page name, "unhandled error" and a count of the number of errors recorded that day...not too helpful.
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36692440
it's a good practice to use log4net or equivalent to log errors. this way if you have a bug you will have more info.
0
 

Author Comment

by:TimSweet220
ID: 36709947
There is log4net on the pages....

{
    public static log4net.ILog log;

    public LogOut()
    {
        log4net.Config.XmlConfigurator.Configure();
        log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    }


and
        log4net.ThreadContext.Properties["Action"] = "Logout";
        log.Info("User Logged Out");

0
 

Author Comment

by:TimSweet220
ID: 36711119
This was great.  I've discovered the error issue.

Seems that when the session is terminated (either by the user clicking log out, session timing out or connection lost to the database)  the menus on the page are still active.  

I can ask what to do here or I can generate a  new question.

0
 
LVL 15

Expert Comment

by:Eyal
ID: 36714380
generate a new question
0
 

Author Closing Comment

by:TimSweet220
ID: 36717172
Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question