SignalR在生产服务器上不起作用 [英] SignalR not working on production server
本文介绍了SignalR在生产服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正打算使用一个简单的SignalR示例,并且由于以下原因,我得到了404代码-
I am tring to utilize a simple SignalR sample and from a reason I get the 404 code from the following -
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
我检查了SignalR文档,并根据提示仍然更改了404状态代码,更改了web.config.
I checked the SignalR documentation and changed my web.config according to what is suggests there still I get that 404 status code.
我的代码如下-
Web.Config:
Web.Config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<httpRuntime/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>
Default.aspx:
Default.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-0.5.3.min.js" type="text/javascript"></script>
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//var connection = new Connection( "127.0.0.1");
// Proxy created on the fly
var chat = $.connection.chatt;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$("#broadcast").click(function () {
// Call the chat method on the server
chat.send($('#msg').val());
});
// Start the connection
$.connection.hub.start();
});
</script>
</head>
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</ul>
</html>
请协助.
推荐答案
我遇到了同样的问题,解决方案是将其放在您的Global.asax文件中:
I had this same problem, the solution is putting this in your Global.asax file:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
}
不幸的是,即使它是SignalR配置的重要组成部分,也未在任何地方进行记录.
Unfortunately this isn't documented anywhere, even though it's an essential part of SignalR configuration...
这篇关于SignalR在生产服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文