Hello,
I am developing a WebSite in ASP.NET CORE MVC that uses Identity Framework for User Authentication. The WebSite heavily relies on User being logged in. In order, to improve user experience I am using AJAX calls for things such as populating some views etc....
The problem that I encounter is that if the ajax calls are making a calls to an action inside a controller that is decorated with an attribute [Authorize] I can get a 401 response while still being logged in on the website. To make matters worse the problem is inconsistent, meaning it can work or it can't . My take on it that it has something to do with cookies that identity framework is using.
I spend a week online looking for a solution and could not find anyone with the similar problem. Is it a bad idea to make ajax calls when using identity framework? should I have an independent authentication mechanism for ajax calls ? Or am I implementing something wrong in the initial solution. Thank you !