Always write it down the first time
I have now encountered this problem twice and it’s my own fault for not writing it down the first time it happened. The problem was extremely obscure and wasted many hours of my time.
Obscure problem
- You have a web application that uses Forms Authentication
- The code has been working fine for months if not years because it’s boiler plate code
- You are absolutely sure that you are logging in with the correct credentials
- However upon first inspection `Response.IsAuthenticated` is always false after login redirect no matter what you do
- You notice that the Forms Authentication cookie is missing
- Upon deeper inspection you see that the login cookie is already expired upon issuance before redirect
In my case, this problem is particularly aggravating because it has absolutely nothing to do with coding assuming we are talking about the same problem. You can scour the internet for solutions on this and you will never find the answer until it dawns on you that you made a mistake by ignoring a minor detail that seems like it’s harmless.
Infuriating solution
Root cause
I cannot guarantee that this is a fix to your problem as the root cause is very specific.
- Are you using a virtual machine for your development?
- For argument’s sake, assuming Window 10 Pro virtual machine as a guest on a physical host machine
- Does your guest machine show that it does not have an internet connection?
- Even though it shows no internet connection it still can access the internet?
- Does your guest machine show that the time is wrong?
- Does your guest machine show that it does not have an internet connection?
If you answered yes to any of that, then restart your guest machine.
Ensure after start up that at the very least your guest machine’s clock is correct and matches the host machine’s time. If the time is wrong – don’t work with any time dependent operations as they will malfunction.
The Forms Authentication Ticket and ASP.Net authentication cookie are time dependent which is why after issuance they were already expired because the operating system’s clock was wrong and failing.
Real world example
This has happened to me twice because I didn’t document this the first time it happened to me so I have wasted over eight hours of effort performing futile code changes to fix a non-existent problem. A complete albatross and waste of time. The amount of anger I felt when I realized what the problem was I cannot put into words. Wasting half a day of my weekend not getting anything done on my personal project is just criminal. Unfortunately, I have no one to blame except myself for not noticing sooner or taking it seriously when I did notice it and say to myself, “Hrmmmm that’s weird the clock is wrong. Ah, who cares, it’s just the wrong time.”
My setup
I do all of my development out of a Virtual Machine that runs Windows 10 Professional. The virtual machine is hosted on my primary desktop machine which also runs Windows 10 Professional. I am using VMWare workstation player. It’s not perfect and I have had a variety of strange behaviors with VMs on my setup. A restart of the VM generally always fixes the issue – don’t know why.
Instance 1
I noticed that my guest machine was showing no internet connection, but I still had internet access. I ignored this because everything was fine as far as I was concerned. I tried logging into my application and could not. About four hours of meaningless debug later I realized that the clock was wrong on the virtual machine too. Restarted the virtual machine and login worked again.
Instance 2
I noticed that my guest machine was showing no internet connection, internet worked fine and the clock’s time was wrong. Stupidly I ignored this again and said to myself, “Man… this feels familiar”. I tried logging into my application and could not. About four hours of meaningless debug later I realized that the clock was wrong on the virtual machine too. Cussed my frustrations out because I realized I had done this before and restarted the virtual machine. Started working for the first time properly that day.