[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unhandled Errors in Logout page

Posted on 2011-09-23
11
Medium Priority
?
326 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 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
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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 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