PC Review


Reply
Thread Tools Rate Thread

Cookies during error handling

 
 
Marty McDonald
Guest
Posts: n/a
 
      21st Jun 2010
In global.asax we handle the application error event by gathering
exception info & putting it into a cookie. Then asp.net automatically
directs the user to our error page, where we use the cookie to show
descriptive error info. Our error page also deletes the cookie like
this...
//Remove cookie from response buffer, so deletion is effective server-
side.
if (context.Response.Cookies[cookieName] != null)
{
context.Response.Cookies.Remove(cookieName);
}

//Send an expired cookie to the client, to force deletion client-side.
if (context.Request.Cookies[cookieName] != null)
{
HttpCookie expiredCookie = new HttpCookie(cookieName);
expiredCookie.Expires = DateTime.Now.AddDays(-1d);
context.Response.Cookies.Add(expiredCookie);
}

Yet when the user navigates back to the app start page, the error
cookie is still present, which causes our app problems (if the error
cookie is present, our app skips certain logic). This is the code
that gets executed after the cookies are supposedly deleted as the
user is navigating away from the error page and to the app start
page...

public void Application_AuthenticateRequest(Object s, EventArgs e)
{
HttpCookie cookie = Request.Cookies["DiagnosticMessage"];
if (cookie != null) <====== The cookie is present here.
{
return;
}

Why would the cookie still be present? Thanks
 
Reply With Quote
 
 
 
 
Marty McDonald
Guest
Posts: n/a
 
      21st Jun 2010
On Jun 21, 11:49*am, Marty McDonald <mp4...@gmail.com> wrote:
> In global.asax we handle the application error event by gathering
> exception info & putting it into a cookie. *Then asp.net automatically
> directs the user to our error page, where we use the cookie to show
> descriptive error info. *Our error page also deletes the cookie like
> this...
> //Remove cookie from response buffer, so deletion is effective server-
> side.
> if (context.Response.Cookies[cookieName] != null)
> {
> * * context.Response.Cookies.Remove(cookieName);
>
> }
>
> //Send an expired cookie to the client, to force deletion client-side.
> if (context.Request.Cookies[cookieName] != null)
> {
> * * HttpCookie expiredCookie = new HttpCookie(cookieName);
> * * expiredCookie.Expires = DateTime.Now.AddDays(-1d);
> * * context.Response.Cookies.Add(expiredCookie);
>
> }
>
> Yet when the user navigates back to the app start page, the error
> cookie is still present, which causes our app problems (if the error
> cookie is present, our app skips certain logic). *This is the code
> that gets executed after the cookies are supposedly deleted as the
> user is navigating away from the error page and to the app start
> page...
>
> public void Application_AuthenticateRequest(Object s, EventArgs e)
> {
> * * HttpCookie cookie = Request.Cookies["DiagnosticMessage"];
> * * if (cookie != null) *<====== The cookie is present here.
> * * {
> * * * * return;
> * * }
>
> Why would the cookie still be present? *Thanks


We found the cause. Our error page set the cookie's expiration to
"yesterday" as it should have. But then it did this...
Response.Cookies.Clear();
....which I believe clears the expired cookie before it ever gets a
chance to be sent to the client. So the only cookie on the client was
the non-expired one.
Our solution was to get rid of the Response.Cookies.Clear() line.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: Cookies handling in various browsers - IE best! Dr Teeth Windows XP Internet Explorer 3 9th Oct 2006 02:27 AM
Handling cookies? Kenny Windows XP Basics 2 1st May 2006 10:48 PM
Error handling with a handling routine =?Utf-8?B?YmVu?= Microsoft Excel Programming 0 15th Mar 2005 03:01 PM
Cookie Handling: Sending saved cookies in httprequest =?Utf-8?B?SmF2YURvYw==?= Microsoft Dot NET 0 21st Jan 2005 12:21 PM
Question about best practices with SqlConnection, error handling and memory handling Lars-Erik Aabech Microsoft ADO .NET 9 17th Apr 2004 06:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:53 AM.