对于我的一个项目,我必须使用DNN。我创建了一个常规的ASP.NET项目,在该项目中我试用了SignalR,并且效果很好。
但是在DNN版本8中,在安装SignalR NuGet软件包后,同时安装了Core和JS并创建了诸如此类的启动类:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
一个testhub类,例如:
public class MyTestHub : Hub
{
public void Hello(string message)
{
//Clients.All.hello();
// set all clients
var clients = Clients.All;
// call javascript function
clients.test("This is a test");
Trace.WriteLine(message);
}
}
最后是索引页:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
DNN 8 SignalR TestPage
</div>
</body>
</html>
<script src="~/DesktopModules/MVC/AC_ChatTest1/Scripts/jquery.signalR-2.4.1.min.js"></script>
<script src="~/signalr/hubs"></script>
<script>
$(function () {
console.log('in on ready');
// set up the hub connection
var hub = $.connection.mytest;
console.log(hub);
// define JS function that is called from
hub.client.test = function (msg) {
console.log(msg);
}
$.connection.hub
.start()
.done(function () {
hub.server.hello("SignalR is working.");
})
});
</script>
我收到此错误:
您是否在DNN模块的上下文中这样做?
如果是这样,您应该看一下:https://www.chrishammond.com/Blog/itemid/2624/using-signalr-with-dotnetnuke-modules。克里斯的模块在GitHub上也可用。
如果没有,您应该切换到模块,并采用Chris的解决方案认真对待。
我认为:
// set up the hub connection
var hub = $.connection.mytest;
应该是:
// set up the hub connection
var hub = $.connection.myTestHub;
我知道了,这些是使signalR在DNN 7.1+中工作所需的步骤:
[assembly: OwinStartup(typeof(Startup))] namespace MyNamespace.MyModuleName { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } }
IF NOT EXISTS (SELECT * FROM dbo.hostsettings WHERE SettingName = 'AUM_DoNotRewriteRegEx' ) insert into dbo.hostsettings (SettingName , SettingValue , SettingIsSecure , CreatedByUserId , CreatedOnDate , LastModifiedByUserId , LastModifiedOnDate ) values( 'AUM_DoNotRewriteRegEx' ,'/DesktopModules/|/Providers|/LinkClick\.aspx|/SignalR' , 0 , -1 , GETDATE() , -1 , GETDATE() ) GO IF EXISTS (SELECT * FROM dbo.hostsettings WHERE SettingName = 'AUM_DoNotRewriteRegEx' and SettingValue not like '%/signalr%' ) update dbo.hostsettings set settingValue = (select settingValue + '|/signalr' from dbo.hostsettings where settingname = 'AUM_DoNotRewriteRegEx') where settingname = 'AUM_DoNotRewriteRegEx' GO