Home > Net >  ASP.NET - how to automatically refresh element's value for multiple users
ASP.NET - how to automatically refresh element's value for multiple users

Time:11-08

I am real ASP.Net beginner and I could use advice from someone wiser than me to give me direction where to look and what to learn.

I am working on ASP.Net/C# webapp for our dept (target .Net is 4.8).

In short: I need to update page for multiple users every time certain value changes in the code behind and do it as fast as possible

Long: There is mandatory feature I can't bypass. Situation: 50 users will be on the same aspx page, watching it. There will be field with certain value. (it can be text field or whatever element will help me to achieve this). Admins can change the value of this element by clicking one of the related buttons. If such event happens, it is absolutely crucial to reflect this change in all of the browsers simultaneously and as fast as possible. Miliseconds matters. (not my idea)

What would be the best way to achieve this?

Please excuse me if my question is too silly. I am not expecting some sample/solution code on such badly formulated question, just general direction where to look (what to learn) as I could not find any solution so far. There should be something since it kind of resembles auction system, you bid, others see it immediatelly and can take action.

thank you in advance

CodePudding user response:

Your use case seems to fit well with the usage of signal-r.

Basically you need something which allows you to set a bidirectional communication between the client and the server, so that you are able to broadcast a message from the server to all the connected clients whenever something important happens on the server.

You can start from the official documentation. This topic is broad, so you need to first of all read the docs and play with some of the provided sample applications. The advantage of this framework for real time web applications is that it fits really well in the ASP.NET and ASP.NET core ecosystem.

Avoid any solution based on client polling of the server state, by doing so you will basically ddos yourself. A push-based solution (like the one offered by signal-r) is way more efficient.

CodePudding user response:

Assuming that a changed value is persisted to the database, there are many solutions to this issue. The most trivial solution consists of setting a timeout timer that checks every n seconds if the current value is different from the persisted and updates page accordingly (Database value).

A more complex, yet elegant solution would be the implementation of a notification system. For instance, if you are using SQL server as your database repository, you can implement SQL dependency; this will allow you to broadcast a message from the database to all sessions (users) that notify them that a change has occurred.

  • Related