使用来自代码的signalr更新ASP.NET镜像 [英] Update ASP.NET image using signalr from code behind
本文介绍了使用来自代码的signalr更新ASP.NET镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是SignalR的新手。我试图让我的ASP.Net网站在点击按钮后为所有客户更新图像。单击按钮后,在服务器端(VB.NET)完成一些计算,理想情况下,它会将更新推送到所有客户端的映像。当我运行它时,我没有得到任何错误但没有任何反应。任何帮助将不胜感激!
我尝试过:
启动页面
I am very new to SignalR. I am trying to make my ASP.Net website update an image for all clients after a button is clicked. After the button is clicked some computation is done at the server side(VB.NET) and ideally it would push an update to the image for all clients. When I run it, I don't get any errors but nothing happens. Any help would be greatly appreciated!
What I have tried:
Startup Page
Imports Microsoft.Owin
Imports Owin
<Assembly: OwinStartup(GetType(ImageHub.Startup))>
Namespace ImageHub
Public Class Startup
Public Sub Configuration(ByVal app As IAppBuilder)
app.MapSignalR()
End Sub
End Class
End Namespace
Signal R Hub类
Signal R Hub Class
Imports Microsoft.AspNet.SignalR
Namespace ImageHub
<Hubs.HubName("imageHub")>
Public Class ImageHub
Inherits Hub
Public Sub updateImage(src As String)
Clients.All.updateImage(src)
End Sub
End Class
End Namespace
VB.Net代码背后
VB.Net Code Behind
Dim contextHub = GlobalHost.ConnectionManager.GetHubContext("imageHub")
contextHub.Clients.All.updateImage("www.imageurl.com")
客户端
Client Side
<script type="text/javascript">
$.connection.hub.start().done(function () {
});
var updater = $.connection.imageHub;
updater.client.updateImage = function (image_source) {
$('#img').attr('src',image_source);
};
</script>
推荐答案
.connection.hub.start()。done(function(){
});
var updater =
.connection.hub.start().done(function () { }); var updater =
.connection.imageHub;
updater.client.updateImage = function(image_source){
.connection.imageHub; updater.client.updateImage = function (image_source) {
('#img')。attr('src',image_source);
};
< / script>
('#img').attr('src',image_source); }; </script>
这篇关于使用来自代码的signalr更新ASP.NET镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文