MVC5 Null Reference with facebook login MVC5 Null Reference with facebook login asp.net asp.net

MVC5 Null Reference with facebook login


A quick solution for now.

You have to clear the Session before ExternalLoginCallback. Example.

[HttpPost][AllowAnonymous][ValidateAntiForgeryToken]public ActionResult ExternalLogin(string provider, string returnUrl){    ControllerContext.HttpContext.Session.RemoveAll();    // Request a redirect to the external login provider    return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));}


Upgrading my Owin components from version 3.0.1 to version 3.1.0 fixed this (so far). 3.1.0 was released April 10, 2017.


Clearing the Session as per the reply from Lee (marked as the answer) resolved this issue for us too. We have a pretty stock standard ASP.NET MVC 4 web app with Google and Facebook login also enabled running on Azure Websites and this was driving us nuts.

It would stop working every 12 - 24 hours or somewhere around that time period and restarting the website would make it work for the next period until it happened again.

I do however wonder why clearing the session works... it smells a bit like a framework bug (or perhaps an Azure bug in our case) unless I'm missing something.