davidxc davidxc - 1 year ago 75
ASP.NET (C#) Question

How to remember a Session if the user has visited the 'splash/landing' page

I have this really simple C# to redirect users to a splash page when they enter the


if (Session["homepageHoarding"] == null)

On that 'splash' page:
, there is a link to return to the 'normal' homepage, which of course is:

But it redirects again, thinking that the session doesn't exist, which it doesn't.

How do I get it so that once they've seen the Splash page it remembers that they've seen it? I can't use a global because my terrible web-hosts don't allow it :-(

Many thanks :-)

Answer Source

As said in the comments, use cookies:

bool userVisited = false;
HttpCookie cookie = Request.Cookies["MyCookie"];
if (cookie == null)
    cookie = new HttpCookie("MyCookie");
    cookie.Values.Add("userVisitedSplash", true);
    cookie.Expires = DateTime.Now.AddDays(30); //<-- Sets the expiration date
    cookie.HttpOnly = true;
} else{
     userVisited = cookie.Values["userVisitedSplash"]
} else{
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download