Solved

Unhandled Errors in Logout page

Posted on 2011-09-23
11
316 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
  • 5
  • 4
  • 2
11 Comments
 
LVL 35

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
 
LVL 35

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now