Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:19:03+00:00 2026-06-17T05:19:03+00:00

I am having trouble with the .Expires cookie attribute. It keeps coming back with

  • 0

I am having trouble with the .Expires cookie attribute. It keeps coming back with 01/01/0001 12:00 AM, when I read the cookie back.

Here is the code. I added in the retrieve just below the save solely for debugging purposes. The save and retrieve happen in different places in the same file. I purposely did not specify a Domain, as I want the cookie to exist site wide.

The data shows up nicely, just not the expiration.

Note: I am testing under Visual Studio 2012 running under local host using .Net Framework 4.

System.Web.UI.Page oPage = this.Page;

HttpCookie oCookie = new HttpCookie("UserData");

// Set the cookie value.
oCookie.Secure = false;
oCookie["Field1"] = strField1;
oCookie["Field2"] = strField2;
oCookie.Expires = DateTime.Now.AddDays(1);

// Add the cookie.
oPage.Response.Cookies.Add(oCookie);


// Get the cookie.
oCookie = new HttpCookie("UserData");
oCookie = oPage.Request.Cookies["UserData"];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:19:05+00:00Added an answer on June 17, 2026 at 5:19 am

    The browser will not send anything to the server except the cookie name and value. All of the other properties (expires, domain, path, httponly, …) cannot be retrieved on requests after the cookie has been set.

    The more accepted way to deal with this is to redirect the user to a login page when they try to access a protected resource and display some message along the lines of “You need to log in to view this page. If you were previously logged in, your session may have expired.”

    (Also note that you should be re-setting the cookie on every request, so that the user will not be logged out if they continue to use the site. It’s not clear from your code whether you are doing this or not.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble expiring a cookie in php. here's my code: <?php setcookie('reitinvestor_user', 'null',
Having trouble with each function... Will try to explain by example... In my code,
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
Having trouble getting the following code to work. Calling swapLevel() directly works fine, but
Having trouble with this code, wondering if I'm trying to achieve something impossible. I'm
Having trouble using ajax to retrieve info from a database. I was getting the
From PHP, I'm having trouble getting the browser to delete a cookie. To chase
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
I'm having trouble coming up with this solution logically. I have an accounts table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.