asp.net-mvc – SignalR 2不生成/ signalr / hubs
发布时间:2020-12-16 03:35:16 所属栏目:asp.Net 来源:网络整理
导读:这是页面: script src="~/Scripts/jquery-1.10.2.min.js"/script script src="~/Scripts/jquery.signalR-2.1.2.min.js"/script !--Reference the autogenerated SignalR hub script. -- script src="~/signalr/hubs"/script !--SignalR script to update th
这是页面:
<script src="~/Scripts/jquery-1.10.2.min.js"></script> <script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script> <!--Reference the autogenerated SignalR hub script. --> <script src="~/signalr/hubs"></script> <!--SignalR script to update the chat page and send messages.--> <script> $(function () { // Reference the auto-generated proxy for the hub. var notification = $.connection.notificationHub; // Create a function that the hub can call back to display messages. notification.client.addNewMessage = function (message) { // Add the message to the page. $('#discussion').append('<li><strong>' + '</strong>: ' + htmlEncode(message) + '</li>'); }; // Set initial focus to message input box. $('#message').focus(); // Start the connection. $.connection.hub.start().done(function () { $('#sendmessage').click(function () { // Call the Send method on the hub. chat.server.send($('#message').val()); // Clear text box and reset focus for next comment. $('#message').val('').focus(); }); }); }); // This optional function html-encodes messages for display in the page. function htmlEncode(value) { var encodedValue = $('<div />').text(value).html(); return encodedValue; } </script> 这是集线器类: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; namespace AdminWebApp.Hubs { [HubName("notificationHub")] public class NotificationHub : Hub { public void SendNotification(string message) { Clients.All.addNewMessage(message); } } } Startup.cs: using Microsoft.Owin; using Owin; [assembly: OwinStartupAttribute(typeof(AdminWebApp.Startup))] namespace AdminWebApp { public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } } } 当我尝试访问:http:// localhost:4551 / signalsr / hubs我收到HTTP 404未找到错误,当我尝试运行页面时,我得到: Failed to load resource: the server responded with a status of 404 (Not Found) Uncaught TypeError: Cannot read property 'client' of undefined 我试过这个:signalR : /signalr/hubs is not generated并没有用. 有任何想法吗? 解决方法
在Application_Start事件的Global.asax文件中,您必须注册集线器URL.
protected void Application_Start() { RouteTable.Routes.MapHubs(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 将EF 4.1代码首先将ASP.NET MVC3部署到中等
- 安排电子邮件在asp.net,C#
- asp.net-mvc – 如何在ASP.NET MVC和Entity Framework中扩展
- asp.net – 电子邮件地址中的多个“@”符号与.net 2005不兼
- asp.net – MembershipProvider在代码中更改连接字符串
- TFS 2015构建:是否可以在存储库映射中使用变量?
- 我们可以在ASP.Net WEB API中使用存储库模式和工作单元吗?
- 使用RestSharp发布GZip内容
- asp.net-mvc-4 – 如何在ASP.NET MVC 4上使用SPA热毛巾模板
- asp.net – Do Bundles优先于Routing吗?
推荐文章
站长推荐
- asp.net-mvc – 使用ASP.NET身份重置密码时的令牌
- asp.net-mvc – 从另一个ActionResult返回Action
- asp.net-mvc – 启用SSL时,IIS默认为HTTPS的端口
- asp.net – 什么是错误代码是0x80070001?那我该
- asp.net-mvc – 在mvc 5和web api 2之间共享owin
- 使用ASP.Net和JSON格式化实现jQuery的jgGrid
- asp.net-mvc – 在ASP.NET MVC 2中模板化Html.Di
- asp.net-mvc – 在DropDownList中验证所需的选择
- asp.net – Cookie域优先?
- asp.net core系列 43 Web应用 Session分布式存储
热点阅读