Blazor webassembly pwa session storage not persisting after deployment to Azure

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 answer

  • answered 2021-01-18 18:22 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.

    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.