asp.net刷新网页上的数据库更改 [英] asp.net refresh web page on DB changes

查看:103
本文介绍了asp.net刷新网页上的数据库更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在asp.net网站上工作。
我有一个页面(main.aspx),该页面显示数据库表中的记录。另一个页面(editing.aspx)负责编辑数据库表中的记录。

I'm currently working on an asp.net website. I have a page (main.aspx) which displays records from a database table. Another page (editing.aspx) is responsible for editing records in the DB table.

让我们假设有一个场景,其中有两个用户正在使用网站user1(在session1上) )正在查看main.aspx中的记录,user2(在session2上)正在从edit.aspx编辑数据库表,我想要的是:当user2将更改保存到数据库表中时,刷新user1的main.aspx。

let's assume we have a scenario where two users are using the website, user1 (on session1) is viewing the records in main.aspx, user2 (on session2) is editing the DB table from editing.aspx, what I want is: to refresh main.aspx for user1 when user2 saves his changes to the DB table.

我尝试使用AJAX计时器,该计时器每10秒拉动一次DB进行更改,并刷新UpdatePanel(在其中显示记录),它工作正常,但是我想知道是否有比拉动数据库服务器进行更改更好的方法。

I tried using an AJAX timer that pulls the DB for changes every 10 seconds, and refreshes an UpdatePanel (in which I'm displaying the records), and it works just fine, but I want to know if there'se a better way than pulling the DB server for changes.

谢谢。

推荐答案

如果另一种方法更好,这是有争议的,但是您要寻找的是与服务器的持久连接,该连接可以使服务器向页面发送消息。 .NET有一个很好的库,称为 SignalR ,它可以抽象出细节。它当然可以提高网络效率,但是根据您的用例,更新面板可能就足够了。基本上,使用SignalR时,您将从编辑页面的服务器端代码发送一条消息,该消息将由主页上的JavaScript函数接收。然后,您要么显示数据,要么以某种方式进行刷新。

It is debatable if the other way is better but what you are looking for is persistent connection to the server that lets the server send e message to the page. There is a good library for .NET called SignalR that abstracts away the details. It is certainly more network efficient but depending on your use case the update panel may be good enough. Basically with SignalR you will send a message from the server-side code of your edit page which would be received by a JavaScript function on your main page. Then you either show the data or cause a refresh in some way.

这篇关于asp.net刷新网页上的数据库更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆