Setting Cookie.Expires

Discussion in 'ASP .Net' started by Joe, Mar 6, 2008.

  1. Joe

    Joe Guest

    I'm trying to set the Expires property of a cookie in a control by doing the
    following:
    this.Context.Response.Cookies["mycookie"].Expires =
    DateTime.Today.AddDays(1);

    But when I refresh the page and check the same
    this.Context.Response.Cookies["mycookie"].Expires it has the default date
    1/1/0001.

    Any idea what I'm doing wrong?

    Thanks,
    Joe
     
    Joe, Mar 6, 2008
    #1
    1. Advertisements

  2. Joe

    Joe Guest

    Sorry I made a mistake in the posting. When I check
    this.Context.Request.Cookies["mycookie"].Expires it is the default value.

    "Joe" <> wrote in message
    news:...
    > I'm trying to set the Expires property of a cookie in a control by doing
    > the following:
    > this.Context.Response.Cookies["mycookie"].Expires =
    > DateTime.Today.AddDays(1);
    >
    > But when I refresh the page and check the same
    > this.Context.Response.Cookies["mycookie"].Expires it has the default date
    > 1/1/0001.
    >
    > Any idea what I'm doing wrong?
    >
    > Thanks,
    > Joe
    >
     
    Joe, Mar 6, 2008
    #2
    1. Advertisements

  3. Here is the thing you need to realize.

    Request.cookies and Response.cookies are 2 different collections
    So if you set correct expiration date in Response.Cookie when you check
    Request.Cookie will still have old expiration date.

    There need to be roundtrip to browser and back for Request.Cookie to become
    what you have set it to in previous request.

    George.


    "Joe" <> wrote in message
    news:...
    > Sorry I made a mistake in the posting. When I check
    > this.Context.Request.Cookies["mycookie"].Expires it is the default value.
    >
    > "Joe" <> wrote in message
    > news:...
    >> I'm trying to set the Expires property of a cookie in a control by doing
    >> the following:
    >> this.Context.Response.Cookies["mycookie"].Expires =
    >> DateTime.Today.AddDays(1);
    >>
    >> But when I refresh the page and check the same
    >> this.Context.Response.Cookies["mycookie"].Expires it has the default date
    >> 1/1/0001.
    >>
    >> Any idea what I'm doing wrong?
    >>
    >> Thanks,
    >> Joe
    >>

    >
    >
     
    George Ter-Saakov, Mar 6, 2008
    #3
  4. Joe

    Steven Cheng Guest

    Hi Joe,

    As for the Cookie expire time, it does have been set on the cookie (you add
    into the Response.Cookies collection). The problem that you didn't see the
    expire value the next time the page submit is because the client browser or
    the request http message doesn't include the expire date value. I 've
    performed test by adding cookie with expire date assigned and post the page
    again. I use some utility to trace the http request/response and found that
    the response http message will include expire date(you asigned) for cookie,
    however, thet request message will only include name/value pair for
    cookies.

    I think this is a fixed behavior of webbrowser since it will maintain the
    expire/validation of cookies. If a cookie has expired, the browser will no
    longer send it (and remove it at client).

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we

    can improve the support we provide to you. Please feel free to let my
    manager know what you think of

    the level of service provided. You can send feedback directly to my manager
    at: .

    ==================================================
    Get notification to my posts through email? Please refer to

    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response

    from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take

    approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution.

    The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump

    analysis issues. Issues of this nature are best handled working with a
    dedicated Microsoft Support

    Engineer by contacting Microsoft Customer Support Services (CSS) at

    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: "Joe" <>
    >References: <>
    >Subject: Re: Setting Cookie.Expires
    >Date: Thu, 6 Mar 2008 16:15:16 -0500


    >Sorry I made a mistake in the posting. When I check
    >this.Context.Request.Cookies["mycookie"].Expires it is the default value.
    >
    >"Joe" <> wrote in message
    >news:...
    >> I'm trying to set the Expires property of a cookie in a control by doing
    >> the following:
    >> this.Context.Response.Cookies["mycookie"].Expires =
    >> DateTime.Today.AddDays(1);
    >>
    >> But when I refresh the page and check the same
    >> this.Context.Response.Cookies["mycookie"].Expires it has the default

    date
    >> 1/1/0001.
    >>
    >> Any idea what I'm doing wrong?
    >>
    >> Thanks,
    >> Joe
    >>

    >
    >
    >
     
    Steven Cheng, Mar 7, 2008
    #4
  5. Joe

    Steven Cheng Guest

    Hi Joe,

    Does the information in my last reply help you some? If there is anything
    else need help, welcome to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we

    can improve the support we provide to you. Please feel free to let my
    manager know what you think of

    the level of service provided. You can send feedback directly to my manager
    at: .
    --------------------t
    >From: ("Steven Cheng")
    >Organization: Microsoft
    >Date: Fri, 07 Mar 2008 03:13:05 GMT
    >Subject: Re: Setting Cookie.Expires


    >
    >Hi Joe,
    >
    >As for the Cookie expire time, it does have been set on the cookie (you

    add
    >into the Response.Cookies collection). The problem that you didn't see the
    >expire value the next time the page submit is because the client browser

    or
    >the request http message doesn't include the expire date value. I 've
    >performed test by adding cookie with expire date assigned and post the

    page
    >again. I use some utility to trace the http request/response and found

    that
    >the response http message will include expire date(you asigned) for

    cookie,
    >however, thet request message will only include name/value pair for
    >cookies.
    >
    >I think this is a fixed behavior of webbrowser since it will maintain the
    >expire/validation of cookies. If a cookie has expired, the browser will no
    >longer send it (and remove it at client).
    >
    >Sincerely,
    >
    >Steven Cheng
    >
    >Microsoft MSDN Online Support Lead
    >
    >
    >Delighting our customers is our #1 priority. We welcome your comments and
    >suggestions about how we
    >
    >can improve the support we provide to you. Please feel free to let my
    >manager know what you think of
    >
    >the level of service provided. You can send feedback directly to my

    manager
    >at: .
    >
    >==================================================
    >Get notification to my posts through email? Please refer to
    >
    >http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti

    f
    >ications.
    >
    >Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    >where an initial response
    >
    >from the community or a Microsoft Support
    >Engineer within 1 business day is acceptable. Please note that each follow
    >up response may take
    >
    >approximately 2 business days as the support
    >professional working with you may need further investigation to reach the
    >most efficient resolution.
    >
    >The offering is not appropriate for situations
    >that require urgent, real-time or phone-based interactions or complex
    >project analysis and dump
    >
    >analysis issues. Issues of this nature are best handled working with a
    >dedicated Microsoft Support
    >
    >Engineer by contacting Microsoft Customer Support Services (CSS) at
    >
    >http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >==================================================
    >This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >--------------------
    >>From: "Joe" <>
    >>References: <>
    >>Subject: Re: Setting Cookie.Expires
    >>Date: Thu, 6 Mar 2008 16:15:16 -0500

    >
    >>Sorry I made a mistake in the posting. When I check
    >>this.Context.Request.Cookies["mycookie"].Expires it is the default value.
    >>
    >>"Joe" <> wrote in message
    >>news:...
    >>> I'm trying to set the Expires property of a cookie in a control by

    doing
    >>> the following:
    >>> this.Context.Response.Cookies["mycookie"].Expires =
    >>> DateTime.Today.AddDays(1);
    >>>
    >>> But when I refresh the page and check the same
    >>> this.Context.Response.Cookies["mycookie"].Expires it has the default

    >date
    >>> 1/1/0001.
    >>>
    >>> Any idea what I'm doing wrong?
    >>>
    >>> Thanks,
    >>> Joe
    >>>

    >>
    >>
    >>

    >
    >
     
    Steven Cheng, Mar 11, 2008
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    605
    clintonG
    Dec 30, 2005
  2. Amir Tohidi
    Replies:
    0
    Views:
    1,270
    Amir Tohidi
    Dec 18, 2007
  3. Pete
    Replies:
    0
    Views:
    167
  4. time is life
    Replies:
    3
    Views:
    358
    Dominick Baier
    Apr 2, 2008
  5. Alex Kail
    Replies:
    2
    Views:
    129
    Alex Kail
    Jul 14, 2004
Loading...

Share This Page