Solved

Unhandled Errors in Logout page

Posted on 2011-09-23
11
320 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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