?
Solved

Unhandled Errors in Logout page

Posted on 2011-09-23
11
Medium Priority
?
323 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 1000 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
Industry Leaders: 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 1000 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

765 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