Tuesday, June 21, 2022

ASP.NET MVC Shared Authentication

Have you ever shared authentication between apps before? I have. It has been at least 12 years since I did it and moved on from life. I remember needing the Machine Key in both the web.config files of both applications and maybe a couple more changes in the configuration tags for the Form Authentication but that was it AND that was back in the .aspx days.
So I recently also needed to do this but now it was an MVC Application, I assumed it was the same idea, add the Machine key and a couple of config items and you are good to go. But that did not work. And all I could find in my research was how to shared authentication between CORE apps, we are not currently using CORE, we are using the old ASP.NET MVC.
There is NOT a lot of info out there on this specifically, like an article title "How to set up shared AUTH between two ASP.NET MVC applications in 5-minutes". It was hit and miss so that's why I am posting this. So maybe it might save someone else the headache! I spent 8 hours madly debugging code, trying differnt ideas...having no idea what was different. Maybe MVC is completely different from aspx and maybe they I don't know how the new stuff works...maybe I should not even be a Software Developer...
And then suddenly and finally I noticed a teeny tiny suggestion. Trust me, you would overlook it. You would think that's silly. I am not even going to waste 30 seconds trying it. But I had spent 6 hours already, and from my years of expericence, the tiniest config items is usually the problem.
So I am going to guess, you won't read 99% of what I am writing, I am writing it for myself because I have no where to sing my own praises that I actually solved this problem.
Here it is:
You probably have the machine key config ub both web.configs
You probably have the form tags "NAME" attbritue set for consistentcy in both web.configs
BUT do you have the targetFramework="4.8" in the httpRuntime tag? If not, you are in luck, add it. Done. Works.
httpRuntime targetFramework="4.8"
I am sure you need to put in your specific framework but give it a try. The post I had found was over 7 years old and I KNOW someone else it going to need this.