0

I have a system with a two-stage login.

Stage one is a Company Login which identifies the Company using my system. Stage two is a Staff Login where a member of staff belonging to the above company logs in.

In both stage an option is offered to save certain login details (Location/Company but not password)

A user should be able, if they wish, to set the Company Login Cookie, but not the Staff Cookie, there is no need to set a Staff Cookie without a Company Cookie, although it doesn't really matter if they do!

Stage one login, amongst database checks etc does this:

 If SaveCookie Then
    Dim loginCookie As New HttpCookie("LogInCompany")
    loginCookie.Values("database") = Database
    loginCookie.Values("savedKey") = SavedKey
    loginCookie.Values("samCompanyId") = CompanyId
    loginCookie.Values("samCompanyName") = Common.htmlDecode(CompanyName)
    loginCookie.Expires = Date.Now.AddDays(7)
    HttpContext.Current.Response.Cookies.Add(loginCookie)
End If

Then stage two does this:

If SaveCookie Then
    Dim loginCookie As New HttpCookie("LogInStaff")
    loginCookie.Values("locationId") = locationID
    loginCookie.Expires = Date.Now.AddDays(7)
    HttpContext.Current.Response.Cookies.Add(loginCookie)
End If

Obviously they are entirely separate functions, so I don't think the variable naming being the same is the issue.

What happens is:

  • Company Login successful > Company Cookie is Saved, User proceeds to
  • User Login User Login > User Cookie is Saved, BUT the Company Cookie is deleted.

This is using Chrome, I haven't checked other browsers but Chrome is the most important to me.

I know that this is definitely what is happening as I have checked in the Chrome Console, the Cookies are added and removed as per description above.

Can someone help point out where I am going wrong here?

EDIT - Nothing wrong with this code!

Argh... after a day of messing about with this, it turns out that the Cookie was being cleared by an unexpected, and caught, error in a different, but related section of code! This question can be closed if required, or left ...?

Jamie Hartnoll
  • 6,673
  • 12
  • 53
  • 89
  • local storage is another option. google for it. – polin Dec 12 '13 at 09:05
  • I don't want to use local storage as I can't control expiry and also need to control the form server-side. – Jamie Hartnoll Dec 12 '13 at 09:54
  • @JamieHartnoll Can you check your login function if somehow your `loginCookie` is getting updated during second type login as it is a reference type. Try changing name of cookies to narrow down your query. – Suraj Singh Dec 12 '13 at 09:58
  • Have you tried by creating different HttpCookie Object for "Loginstaff" ? – polin Dec 12 '13 at 11:26
  • Thanks both, I have tried renaming the references but it's not making a difference, it's almost as if I can only have one cookie per domain, but that shouldn't be the case. – Jamie Hartnoll Dec 13 '13 at 09:01
  • 2
    Arrghhhh DOH! It's nothing to do with any of the above - I was clearing the Cookie on an unexpected, and unnoticed error! – Jamie Hartnoll Dec 13 '13 at 09:29

0 Answers0