I encountered a missing Session problem. After days of investigation, I found out the Session is missing when it tries to call AJAX post trigger by SignalR from localhost.
I have a local Windows service that is installed on the same VM where my website (ASP.NET MVC 4 hosted in IIS) is hosted. It will do some tasks and when it is completed, it sends a notification via https://localhost/api/notify. This in turn uses a SignalR to broadcast a message.
When the client browser receives this message, it will do an AJAX call back to /CPanel/OptiTasks/RefreshData (the client will launch the page via an external URL - for example: https://example.com). However, when I tried to retrieve the Session variable, it disappeared.
I have tried to include withCredentials set to true, but the Session variable still disappeared.
In summary, here is the sequence:
- Client login to the website via external URL (eg. https://example.com)
- After login the client goes to page https://example.com/cpanel/optitasks
- On the OptiTasks page, it uses SignalR to listen to the update notification
- Windows Service --- Send Notification Via --> https://localhost/api/notify
- SignalR will broadcast a notification request which will received by the OptiTask page
- OptiTask page will do AJAX post (withCredentials = true) to /cpanel/optitasks/refreshdata
- In RefreshDataController, the Session variable is NULL (eg. Session["MySessionVariable"] is NULL)
I have searched online including using ChatGPT, but I am still unable to figure out how to fix this problem.
Please help.
StateServer. The problem was on the Windows Service, it used ServerManager to make various changes to server configuration (eg. update SSL cert) which caused IIS to recycle the application pool