Missing Session variable in ASP.NET MVC 4

28 Views Asked by At

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:

1. Client login to the website via external URL (eg. https://example.com)
2. After login the client goes to page https://example.com/cpanel/optitasks
3. On the OptiTasks page, it uses SignalR to listen to the update notification
4. Windows Service --- Send Notification Via --> https://localhost/api/notify
5. SignalR will broadcast a notification request which will received by the OptiTask page
6. OptiTask page will do AJAX post (withCredentials = true) to /cpanel/optitasks/refreshdata
7. In RefreshDataController, the Session variable is NULL (eg. Session["MySessionVariable"] is NULL)

I have searched online for days including using ChatGPT, but I am still unable to figure out how to fix this problem.

Please help...

0

There are 0 best solutions below