How to refresh aspx page from sql server.I am using asp.net,C-Sharp with SQL Server 2008.What i mean is i have table, say Table1.If any DML operation is performed (Update,Insert etc) to Table1,then my page,say Page1.aspx should autmatically get refreshed.I can't use timer for refreshing the page.I need to trigger the refresh from database.
Even though the server may be notified when data has changed, the real challenge is communicating those changes to the client in real-time without requiring a timer or user interaction.
You have a couple of options:
Your best bet is to use a WebSocket, which enables bidirectional communication between the client and server. This is the solution I would pick.
Here are some examples using WebSockets:
Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
HTML5 C# WebSockets Server and ASP.NET Client Implementation
C# WebSocket Server
WebSockets in ASP.NET 4.5
WebHooks and WebSockets in ASP.NET
There are a few good libraries around too that will take care of most of the leg work. A couple to check out are WebSync and PokeIn. Both products offer decent documentation and community editions that you can download for free.
Here are some tutorials to check out:
WebSync Tutorials
PokeIn Basic Tutorial / PokeIn Advanced Tutorial
Use AJAX to poll for changes every X number of seconds. If changes are detected reload the page, otherwise do nothing.
You probably want to look into the SqlDependency object. This object will notify you of changes to a specified database query in real time. When your application receives a message from the database, you can simply refresh the page in your code-behind.
I wonder if you could adapt SignalR to send a message to the client to prompt a refresh?
This tutorial could get you started.
Related
I have a web page for data processing. Web page waits for data to process.
And I have a C# application for data. I want to send data to open web page. But I don't want to use socket, Post/Get methods or any web request.
Web page and C# application are client side. They run in same Windows at the same time.
I want to send data to web page from C# app. This operation need to be done with Windows OS or some command line based trigger mechanism.
Web page (Chrome tab or Firefox tab; it doesn't matter) should have tab id the work on. With using this id I may be able to send data to web page from C# app.
But I couldn't really find anything useful.
Is there any way to do this? Is it even possible?
Any advice appreciated.
The way I would approach this is this, assuming you are using either WinForms or WPF:
In your application, embed a web browser:
WPF: https://www.wpf-tutorial.com/misc-controls/the-webbrowser-control/
WinForms: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/webbrowser-control-windows-forms?view=netframeworkdesktop-4.8
Load the web page in that browser
Establish a two-way communication between your client application and the web page:
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/implement-two-way-com-between-dhtml-and-client?view=netframeworkdesktop-4.8
If using other technologies let me know and I'll update answer.
One solution is Raw TCP/IP connection on browser but it's not yet fully supported and implemented. If by Web requests you mean online requests then what #DevRacker said is the best I know, too.
However consider TCP/IP, Web sockets and even REST-APIs are frequently used for Inter-Process Communication (IPC) too, when there is no online transmission of data and the data/command is only transmitted over a local machine.
If I were you, I would use Web sockets or maybe a simpler solution such as Socket-IO.
I have an intranet/extranet app which calls the server to do some VERY LONG calculations. The client should be able to keep surfing the site and doing his stuff, until a message pops up saying the calculation has ended and asking him if he wants to go back to the page to see the results.
If so, the client must be redirected to that page, the data must be retrieved the from the server and displayed. If the user cancels the action, the data set must be cleared.
How do I send a message to the client from C# and how do I catch it? Is it possible?
Thanks
Reactive Extensions (Rx) for .NET deals with exactly this kind of problem. It allows for "push" notifications of remote events.
Here is a blog post that introduces Rx over ASP.NET:
http://weblogs.asp.net/podwysocki/archive/2010/02/16/introduction-to-the-reactive-extensions-to-javascript.aspx
Here's an entire RxJS library:
http://reactive-extensions.github.io/RxJS/
Yes, sending messages from server to client via http possible with using web-sockets or longpolling technologies.
We have a ASP.NET web app that needs to display data in real time or as best s and we are currently using AJAX and web services but this causes performance issues because number of clients is getting bigger and bigger. Data is being pooled every 5-10 seconds and when this is multiplies by 1000+ clients it can make data retrieval quite slow.
You might want to try using SignalR to handle your real-time data needs. From the site:
ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.
You may have heard of WebSockets, a new HTML5 API that enables bi-directional communication between the browser and server. SignalR will use WebSockets under the covers when it's available, and gracefully fallback to other techniques and technologies when it isn't, while your application code stays the same.
SignalR also provides a very simple, high-level API for doing server to client RPC (call JavaScript functions in your clients' browsers from server-side .NET code) in your ASP.NET application, as well as adding useful hooks for connection management, e.g. connect/disconnect events, grouping connections, authorization.
Try one or more of the following:
Caching – can you consider store your application data in memory for some time. That will reduce the impact on the database server.
HTML 5 Server Side events – Using Server Side Events you can actually notify clients (push data instead of pooling) when change happens. You would essentially need one ASP.NET event handler (ashx page) that pushes requests and some JS code on the client side.
Check out this article for more details and code examples on Server Side Events.
I am building a social application and was wondering how facebook achieve their notifications.
As you know, facebooks notifications are instant. As soon as someone takes an action, people are notified.
I assume they don't have a query running on the database all the time.
Can someone point me in the right direction. Thanks
Since your question is tagged with C#, ASP.NET you should use the awesome SignalR library. Basically SignalR enables you to send push notifications to the clients. Which exact underlying technique it uses is influenced by the capabilities of the Server and the Client.
There is a big real time chat site called jabbR that is built on top of SignalR:
http://jabbr.net/
Here are some more links that should get you started.
Project site: http://signalr.net/
Hosted Code (Open Source): https://github.com/SignalR/SignalR
Wiki: https://github.com/SignalR/SignalR/wiki
Projects using it: https://github.com/SignalR/SignalR/wiki/Projects-Using-SignalR
Facebook uses a messaging protocol (which it designed) called Thrift. This allows notifications from clients to servers with very low latency. I would imagine updates on the server would be triggered depending on the user action and relevant users that are logged in would be notified by the same mechanism.
Using a messaging protocol such as thrift (also see Protocol buffers) clients don't have to poll the server for updates, instead the server can push notifications to clients. To do this the server needs to have a notion of who is logged in at any one time (Login, logout handshaking) and of them, who should receive notifications from a particular client action.
Easier said than done, especially when you have 800 million potential users logged in!
You might want to take a look at http://nodejs.org/ - it is an event-driven model which is perfectly ideal for a 'social network' / instant notifications scenario.
FYI: You also might find that using a non-SQL database such as MongoDB (http://www.mongodb.org/) will be a lot faster when querying from the DB since each 'person' object in a social network scenario has his/her own unique attributes - which in a normal SQL database is hard to design.
Hi I wanna make a website preferably using asp.net 3.5 in c#. In this web app, I need to push messages very frequently. (like if sender sends a message, it should immediately reflect to the receivers). So more like chat application but not bidirectional.
My question is how can i refresh receivers webpage immediately?
or How can i push message to the receivers immediately?
any help is highly appreciated?
I'm guessing you're talking about features like Facebook Chat. According to various facebook dev blog posts, I believe they use ajax to make a long polled request; meaning as soon as one user sends a message, theres another ajax request made which isn't responded to by the server until there's something to report (i.e. a new message). This is often called "Comet".
Note: do NOT attempt to do this on a standard server setup - most server software starts a new thread for each request. You'll need custom server software to avoid this. Unfortunately, I've searched for hours in the past and can't find a definitive answer to which software accomplishes this best.
You might consider using a Comet Look at the "implementation" section for some ideas.