-1

I have tried using Hangfire to create a recurring job to run at 3 specific hours daily but i found out later it cannot access httpcontext to signout users, so what i did instead, hangfire task calls a stored procedure at the given hours and I have created a razor pages filter that will signout user depending on a boolean in database that is changed by the task.

I would like to know if is there a way to do this without having to hit the database every http request using the filter. For example,

I would like to log out the user automatically at 6:58am or 14:58pm or 22:58pm

how to achieve this?

Jackal
  • 3,359
  • 4
  • 33
  • 78

1 Answers1

0

You can only sign a user out in the context of a request that specific user is making. The reason for this is simple: authentication is persisted via a cookie on the client. Only through direct interaction with that client (where the client is transmitting the cookie to the server), can you do something about their authenticated state. There is no global store of logins or something that you can simply modify all at once. As a result, you must use the approach of a filter or some piece of middleware in the request pipeline to handle this. There is no other option.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444