HttpModule Cookie Problem

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default HttpModule Cookie Problem

    Hello-

    I wrote a HttpModule to inspect the user's current page and to assign a
    source a content category to them. The problem is that when it runs, it wipes
    out users cookies which logs them out of the site and wipes out their basket.
    I can't recreate the error in any sort of test or staging environment, so I'm
    at a complete loss as to what might be causing this. Any ideas? Here's the
    important bit of my code:

    #region IHttpModule Members

    public void Init(HttpApplication context)
    {
    context.BeginRequest += new EventHandler(OnBeginRequest);
    }

    public void Dispose()
    {
    // TODO: Add CategoryManager.Dispose implementation
    }

    #endregion

    private void OnBeginRequest(object sender, EventArgs e)
    {
    try
    {
    //get the http application
    HttpApplication context = (HttpApplication)sender;

    string pageID = GetPageID(context);
    string categoryID = GetCategoryID(context);
    string source = GetSource(context);

    //add the info that can be preserved to the user's cookie
    HttpCookie categoryCookie = new HttpCookie("cmCategory", categoryID);
    context.Response.Cookies.Add(categoryCookie);

    HttpCookie sourceCookie = new HttpCookie("cmSource", source);
    context.Response.Cookies.Add(sourceCookie);

    //add all values to HttpContext.Items for the actual tags to use
    TaggingSession.PageID = pageID;
    TaggingSession.CategoryID = string.Format("{0}:{1}", source, categoryID);
    //create the composite category with the source and category
    }
    catch(Exception ex)
    {
    ExceptionManager.Publish(ex);
    }
    }

    OnBeginRequest calls a few helper functions (GetSource, GetCategory, etc.).
    These methods only do reads and inspect the Request.Cookie collection, the
    current URL (for querystrings) and an XML file (to look up page IDs). I can
    post that as well, if nevessary, but it's a lot of code to go through.

    Regards-
    Eric
    Eric Marthinsen Guest

  2. Similar Questions and Discussions

    1. Cookie Problem -Please Help
      Hello Everyone, I have a little problem. I want to create a cookie and if the user deciced to close the browser, I want that cookie deleted...
    2. PHP Cookie Problem
      Hi guys, I've got a section of my site where I've integrated a rating script. Seems to work okay expect what I've noticed is that with the...
    3. Cookie problem
      I like cookies, you can send me some "Onur Bozkurt" <onur.bozkurt@softhome.net> wrote in message news:eC9xJP7PDHA.1624@tk2msftngp13.phx.gbl...
    4. problem with cookie
      Jose wrote: i may be wrong on this, but i would be surprised if a cookie's key is allowed to have the apostrophe character in it. Check your...
    5. Problem with IE and Cookie
      Hi Friends, I created a cgi program which make use of the cookies to check user authentication. And for creating cookies i make use of...
  3. #2

    Default Re: HttpModule Cookie Problem

    > //add the info that can be preserved to the user's cookie
    > HttpCookie categoryCookie = new HttpCookie("cmCategory", categoryID);
    > context.Response.Cookies.Add(categoryCookie);
    >
    > HttpCookie sourceCookie = new HttpCookie("cmSource", source);
    > context.Response.Cookies.Add(sourceCookie);
    Strange problem... try tracing the cookies before and after adding.

    Have the following code before and after adding the cookies.
    btw, have you checked the list of cookies at the client (or the raw response
    from the server)?

    foreach(HttpCookie cookie in context.Response.Cookies)
    {
    Trace.Write(...)
    }


    --
    Happy Hacking,
    Gaurav Vaish | [url]http://www.mastergaurav.com[/url]
    [url]http://www.edujinionline.com[/url]
    [url]http://articles.edujinionline.com/webservices[/url]
    -------------------


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139