0
votes

I am developing a Blazor webassembly pwa, locally running the project will store the user in the session storage and keep them there.

But when I deploy to Azure (linux app service) the session/local storage is not persisting. So when navigating to a different page (within my application) or refreshing the page the oidc.user variable is removed from the session storage and therefor my user is logged out.

local working session storage

  • Locally it's working and the key pair will persist.

enter image description here

  • When deployed to Azure the same key will be added after loggin in succesfully but after a redirect it's removed.

So the real question is: Why is my session storage working locally but does it remove the oidc.user key pair after a redirect, Causing the user to be logged out.

1
You said that when you are running your app locally, the token is stored in the local storage. Your screenshot shows the session store. The session store is cleared on refresh. What do you mean by "different page"?. A different @page but within the same blazor application? Is there a reason for not using local storage to persist the token?Just the benno
@Justthebenno Yes a different '@page' within the same application. The token is put in the local storage when logged in, but it is removed when navigating to a different '@page' or refreshing the browser window. The token being removed is my issue, and i do not know why this happens.Mees van Straten
I don't see a value whose Key is something like this: "oidc.user:localhost:44308:BlazorApp1.Client"enet
@enet Exactly, that is my problem. It does get stored for about half a second something like oidc.user etc en then after a redirect or navigating to another page within my application its no longer there. Because of that my user now is logged out. This problem only is here after deploying, running it locally works.Mees van Straten

1 Answers

0
votes

Exactly, that is my problem. It does get stored for about half a second something like oidc.user etc en then after a redirect or navigating to another page within my application its no longer there. Because of that my user now is logged out. This problem only is here after deploying, running it locally works.

It seems as though the session cookie is being deleted immediately after a request is made. Note: The cookie session ID is sent to the server at each request.

This may be only a guesswork, but you better try it than not...

Add the following code to your CongiureServices:

   services.AddDistributedMemoryCache();

    services.AddSession(options =>
    {
        options.IdleTimeout = TimeSpan.FromSeconds(600);
        options.Cookie.HttpOnly = true;
        options.Cookie.IsEssential = true;
    });

And app.UseSession(); in the Configure method, immediately above app.UseEndpoints(endpoints =>

Hope this works...

Note: AuthenticationStateProvider has got nothing to do with the issue you're facing.