I have a Blazor web Assembly that runs on windows and the Web I want to log out the user when the Windows/Tab closes.
Is it possible to do it without JavaScript? if yes how can we do it by using C#? if not then how can we do it by using JavaScript?
I have a Blazor web Assembly that runs on windows and the Web I want to log out the user when the Windows/Tab closes.
Is it possible to do it without JavaScript? if yes how can we do it by using C#? if not then how can we do it by using JavaScript?
I don't think it will possible without Javascript as you will likely need to tie into the window.onbeforeunload
. Your application could include a script that creates a handler for this event and execute some logic to perform your logout routine. There are some caveats here. Your logout routine cannot be async as the browser will likely kill the thread before the async routine completes.
Depending on how you implemented your client side authorization you should just be able to clear a cookie or some other persisted data in the browser that lets the application know the user is logged in. If you need to send a request back to the server you could send an synchronous ajax request using Javascript but this may not be supported by some browser. I do believe that chrome supports it.
This post window.onbeforeunload ajax request in Chrome provides some details about how to implement this in Javascript.