简体   繁体   English

使用signalr和sqldependency在asp.net核心中进行数据库更改通知

[英]Database change notifications in asp.net core using signalr and sqldependency

If I made any changes in SQL table row then UI should automatically refresh the new changes without F5 or reloading the browser. 如果我在SQL表行中进行了任何更改,那么UI应该在没有F5或重新加载浏览器的情况下自动刷新新的更改。

I have already tried this in asp.net mvc and its working good but I'm unable to do in asp.net mvc core.. 我已经在asp.net mvc中尝试了这个并且它的工作正常,但是我无法在asp.net mvc核心中做到这一点。

You are looking for a sql backplane solution which as of now and this github isssue , is not supported under core. 您正在寻找一个sql背板解决方案,截至目前,这个github isssue ,在核心下不受支持。

Read that issue for more details. 阅读该问题了解更多详情。 But they are recommending the use of a Redis backplane which is support as in the documentation . 但他们建议使用Redis背板,这是支持文档中的支持。

You can detect changes using the SqlDependency class and then broadcast them to registered clients using SignalR. 您可以使用SqlDependency类检测更改,然后使用SignalR将它们广播到已注册的客户端。 I wrote a sample using pre-Core SignalR, which is available at https://weblogs.asp.net/ricardoperes/broadcasting-database-changes-through-signalr . 我使用pre-Core SignalR编写了一个示例,可以在https://weblogs.asp.net/ricardoperes/broadcasting-database-changes-through-signalr上找到 In order to make it work with ASP.NET Core SignalR you need to retrieve the hub using the service locator (HttpContext.RequestServices.GetService>). 为了使其与ASP.NET Core SignalR一起使用,您需要使用服务定位器(HttpContext.RequestServices.GetService>)检索集线器。 Also, there is a change that you must do to the client-side code. 此外,您必须对客户端代码进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM