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

  • Home
  • SEARCH
  • 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 7013895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:27:00+00:00 2026-05-27T22:27:00+00:00

I have a page where a user logs in to a back-end application via

  • 0

I have a page where a user logs in to a back-end application via a web service. The web service returns a session ID which I want to store in a cookie for 40 minutes, as after 40 minutes the back-end application automatically closes the session.

My code to write the cookie:

private void SetCookie()
{
    Response.Cookies.Add(new HttpCookie("Cookie_SessionID"));
    Response.Cookies["Cookie_SessionID"].Value = ni.NicheSessionID;
    Response.Cookies["Cookie_SessionID"].Expires = DateTime.Now.AddMinutes(40);

    //.... after a few more things
    Response.Redirect(returnUrl);
}

Then on the receiving page I have this:

private HttpCookie GetCookie()
{
    HttpCookie cookie = Request.Cookies["Cookie_SessionID"];
    if (cookie != null && cookie.Value != null)
    {            
        return cookie;
    }
    return null;        
}

For some reason the cookie returned by GetCookie() always has an Expires value of 0001-01-01 00:00:00, even though when I view cookies in the browser it has the correct expiry time.

Having read this which states expired cookies are simply not sent to the server, I assume what could be happening is that the cookie is being written correctly but the browser is not sending the expiry date because it’s actually unnecessary?…

My problem is that I want to capture precisely that – the cookie has ‘expired’ and so they have to log in again – but I need to display a message along the lines of “I know you have already logged in but you’ll need to do it again” type thing.

Thanks

  • 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-05-27T22:27:01+00:00Added an answer on May 27, 2026 at 10:27 pm

    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.

    If you want to display such a message then you will need some other mechanism of detecting that the user was logged in. You might set a presence cookie for a year or so and check to see if it exists.

    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 have a page upon which a user can choose up to many different
We have a page of search results which the user can hit in several
I have a web page where the user will enter their address. They will
On session timeout we re-direct to the login page and if the user logs
I have a PHP / Javascript page that automatically logs a user into different
I have created a new MVC2 project using the ASP.NET MVC2 Web Application, which
We have an application which starts on a logon page and then navigates to
I have a JSF 2.0 page where the user logs in and he has
I need something simple; I have page where a user clicks an author to
I have a page where a user can import data to the site. either

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.