I’m working on a Blazor server-side app. In some cases, when a user updates a resource, the application will show a toast asking if the user wants to refresh their view (or not) since if you’re in the middle of analyzing something you may not want the refresh to happen just yet.
The toast is fired by a system level event and not a local function, since events have to go to other logged in users (and sometimes users who haven’t even logged in yet– they get the notice once they log in).
The thing is that I don’t want the window that made the change to get these toasts, since the change originated there– I just want other logged in windows to get the toast, whether the window is logged in as the same user or another user.
Dealing with different users is pretty easy to handle– I can just pass in the logged in userID
to the toast and not show the toast if the ID matches the current user. My problem is, if the user who made the change is logged in with multiple open browser windows, how can I show the toast on one user window but not the other?
I’m thinking if I add an originationID
to the toast object and assign it a value that’s unique to the window session, then when the toast gets fired it can see if that ID matched the current window session ID, and if they match ignore the toast.
Is there a unique window ID that is associated with one browser window (in blazor) but not the other window owned by the same user? I was hoping the thread ID might be a useable way to tell which window originated the toast event, but that ID seems to change frequently even when the window is merely changing location.
0
Create a Scoped Id service:
public class SPAIdService
{
public Guid SPAId { get; private set; }
public bool IsThisSession(Guid value)
=> SPAId == value;
}
And register it as scoped. The Id will be the same for the user SPA session.