1

We have a blazor server application in production and the issue is that users usually are filling forms while spending time on other browser tabs, and they leave the blazor server tab open for hours. When they come back to the tab, the connection to the server is lost and they have to reload the page. The issue is that at refresh they loose the data that they added in the application inputs which creates a bad user experience.

I looked into this question but is seems that the solution involves page reloading.

I there any way I can automatically reconnect to the server without refreshing the page ?

Daniel
  • 261
  • 3
  • 18

2 Answers2

3

One solution for this would be to use the browsers storage, either the session or local storage (I'm pretty sure session storage would be lost on disconnect though I'm not 100% sure) here is Microsoft's documentation on browser storage.

Whenever they fill something on the form out you push it to the browser's storage and if for whatever reason they lose connection and reconnect you check their browser for any data and pull it.

Just remember that if you use local storage they can open multiple tabs and have access to the same data.

From what I've seen the usual recommendation is to use Blazored Local Storage.

Can also use cookies to accomplish the same effect as well.

Kyle Cintron
  • 316
  • 2
  • 6
2

I don't think so. You wouldn't want the server to be maintaining the state of dead pages indefinitely.

If these users can be identified (for example by logging them in), then it's trivial to keep state. You can use a SQL database to store a JSON string of the current state of the input model, for example. Or you can use a singleton service with data keyed to the user.

Bennyboy1973
  • 3,413
  • 2
  • 11
  • 16
  • I also looked into this question : https://stackoverflow.com/questions/60057826/blazor-server-side-app-on-iis-frequently-disconnects-websocket-connection Maybe modifying websockets timeout could be a solution ? – Daniel Sep 15 '21 at 12:50
  • I've investigated this stuff only briefly, but actually I'm running a web-based game server, so I'm going to have to improve my knowledge on this stuff. Please do come back and let us know if you were able to answer the question, or find info that is leading you in the right direction. I'm currently having trouble with test users who are on a bad wifi connection getting dropped completely-- probably not the same issue, but same ballpark. – Bennyboy1973 Sep 15 '21 at 20:40