This issue can drive you mad. It was driving me mad, and I wasted an afternoon on this. I was working on a legacy site that was created with ASPX pages (webforms) and has a bit of age on it. I’m currently working on more API / Angular type sites so this webforms site is rather old (5-15 years). The site is an active commercially used site, so in general I have to assume it is working fairly well, and I was just asked to add a bit of new functionality.
As I was testing a page, and I had several break points set in the code behind, it would hit my break points and I would start walking through my code. At random times, the browser would jump to the login screen and leave my break point. This made no sense, and I assumed there was something wired up in this application that I wasn’t aware of, that must be running in the background. There were never any errors thrown. Repeat… No errors were occurring.
I think I found the issue to be related to Forms Authentication. This particular app isn’t using Forms Authentication for security and has it’s own custom authentication code, however Form Authentication was enabled in the web.config (as I’m sure it has been in most of the ASPX applications I worked on).
Here’s how I fixed it:
Find this in your web.config file and remove it or comment it out.
<authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" defaultUrl="~/" /> </authentication>
Hoping this saves me or someone else many wasted hours in the future.