- ABP Framework version: v8.0.0
- UI Type: Blazor Server
- Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)
- Tiered (for MVC) or Auth Server Separated (for Angular): no
- Exception message and full stack trace:
- Steps to reproduce the issue: How can I clear all session storage after logout? ISessionStorage does not allow in LogoutModel as we need to implement it in OnAfterRender
8 Answer(s)
-
0
Hello ,
Please check this solution if it works for you https://stackoverflow.com/questions/77204224/how-to-clear-all-the-sessions-using-protectedsessionstorage-in-blazor-server-app.
Thank you.
-
0
It does not work for me, if using sessionStorage.Clear(), I cannot call it from OnGetAsync method in LogoutModel
-
0
-
0
As I mentioned, it raises error InvalidOperationException: JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.
There is no method OnAfterRenderAsync in LogoutModel to overwrite
-
0
@Anjali_Musmade do you have any other idea? Thanks
-
0
Hi,
You can try this:
public partial class Index { [SupplyParameterFromQuery] public string Page { get; set; } [Inject] public IJSRuntime JsRuntime { get; set; } protected async override Task OnInitializedAsync() { if (Page == "/Account/~/Account/Login") { await JsRuntime.InvokeVoidAsync("sessionStorage.clear"); } } }
-
0
Thank you, this solution seems work for me BTW, I added to OnAfterRenderAsync protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { //Temporary solution to clear session storage if (Page == "/Account/~/Account/Login") { await jsRuntime.InvokeVoidAsync("sessionStorage.clear"); } } await base.OnAfterRenderAsync(firstRender); }
-
0
It's ok.