locked
Database Changed Item Show Alert() For SignalR RRS feed

  • Question

  • User-1795663842 posted

    Hey , I using SignalR and Entity Framework .

    Question : From the moment data changes SqlServer?

    Thanks for help  

    Code : 

    public ActionResult VeriGetir()
         {
                var model= context.SignalRTest.OrderByDescending(z => z.Id).FirstOrDefault();
                return Json(model,JsonRequestBehavior.AllowGet); 
                
         }
    public class BildirimHub : Hub
       {       
            public static void SendMessages()
            {
                IHubContext context = GlobalHost.ConnectionManager.GetHubContext<BildirimHub>();
                context.Clients.All.updateMessages();
            }
        }
    <pre><script src="~/Scripts/jquery.signalR-2.3.0.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="/signalr/hubs"></script>
    
        <script type="text/javascript">
            $(function () {
                var notifications = $.connection.bildirimHub;
                notifications.client.updateMessages = function () {
                    ClientControll()
                };
            function ClientControll() {
                $.ajax({
                    url: '/Home/VeriGetir',
                    contentType: 'application/json; charset=utf-8',
                    type: 'GET',
                    dataType: 'json',
                    success: function (result) {
                        alert(result.Mesaj)
                    }
                })
            }
        </script>
    Sunday, September 30, 2018 7:31 PM

Answers

  • User61956409 posted

    Hi ynsbldk,

    According to your code and description, it seems that you'd like to push database updates to connecting users via ASP.NET SignalR technology. In your code I can find you define a hub method SendMessages(), but you do not call it in anywhere. 

    Please refer to the following links to establish connection and call hub method from your JavaScript client:

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 1, 2018 2:00 AM