asp.net mvc4 signalR后台自推送
1.在引用中添加signalr后首选要引入Startup.cs类,在VS2012中添加Signalr后没有Startup.cs类然后就会报错 代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; using Owin;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(CarportManage.Startup))]
namespace CarportManage
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}
2写一个发送类
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace CarportManage.Models
{
public class seedmessage:Hub
{
public void Send(object message)
{
IHubContext chat = GlobalHost.ConnectionManager.GetHubContext<seedmessage>();
chat.Clients.All.add(message); }
}
}
3后台代码调用发送类
using CarportManage.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace CarportManage.Controllers
{
public class AlertController : Controller
{
//
// GET: /Alert/
CardManageEntities3 db = new CardManageEntities3();
public ActionResult Index()
{
return View();
}
public ActionResult show()
{
return View();
}
public ActionResult insert(FormCollection from)
{
int success;
try
{ CardManage t = new CardManage();
t.userName = from["add_name"];
t.userTel = from["add_tel"];
t.carNum = from["add_carNum"];
t.userDep = from["add_dep"];
t.fixedCarport = from["add_fixedCarport"];
db.CardManage.Add(t);
db.SaveChanges();
seedmessage s = new seedmessage(); s.Send(t);
success = ; }
catch (Exception)
{
success = ; }
//new { success = true }
return Content(success.ToString());
} }
}
4前端代码块
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery.signalR-2.1.2.js"></script>
<script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
var pushHub = $.connection.seedmessage; pushHub.client.add= function (message) { alert(message.userName);
alert(message.userTel);
}
$.connection.hub.start();
</script>
<title>接收端</title>
</head>
<body>
<div> </div>
</body>
</html>
asp.net mvc4 signalR后台自推送的更多相关文章
- AngularJS+ASP.NET MVC+SignalR实现消息推送
原文:AngularJS+ASP.NET MVC+SignalR实现消息推送 背景 OA管理系统中,员工提交申请单,消息实时通知到相关人员及时进行审批,审批之后将结果推送给用户. 技术选择 最开始发现 ...
- ASP.NET MVC SignalR 简单聊天推送笔记
介绍:(抄袭于网络) ASP.NET SignalR 是为 ASP.NET 开发人员提供的一个库,可以简化开发人员将实时 Web 功能添加到应用程序的过程.实时 Web 功能是指这样一种功能:当所连接 ...
- 使用SignalR ASP.NET Core来简单实现一个后台实时推送数据给Echarts展示图表的功能
什么是 SignalR ASP.NET Core ASP.NET Core SignalR 是一种开放源代码库,可简化将实时 web 功能添加到应用程序的功能. 实时 web 功能使服务器端代码可以立 ...
- 基于SignalR的消息推送与二维码描登录实现
1 概要说明 使用微信扫描登录相信大家都不会陌生吧,二维码与手机结合产生了不同应用场景,基于二维码的应用更是比较广泛.为了满足ios.android客户端与web短信平台的结合,特开发了基于Singl ...
- PHP Web实时消息后台服务器推送技术---GoEasy
越来越多的项目需要用到实时消息的推送与接收,怎样用php实现最方便呢?我这里推荐大家使用GoEasy, 它是一款第三方推送服务平台,使用它的API可以轻松搞定实时推送! 浏览器兼容性:GoEasy推送 ...
- Ruby Web实时消息后台服务器推送技术---GoEasy
越来越多的项目需要用到实时消息的推送与接收,怎样用Ruby实现最方便呢?我这里推荐大家使用GoEasy, 它是一款第三方推送服务平台,使用它的API可以轻松搞定实时推送! 浏览器兼容性:GoEasy推 ...
- JAVA Web实时消息后台服务器推送技术---GoEasy
---恢复内容开始--- 越来越多的项目需要用到实时消息的推送与接收,我这里推荐大家使用GoEasy, 它是一款第三方推送服务平台,使用它的API可以轻松搞定实时推送! 浏览器兼容性:GoEasy推送 ...
- Signalr实现消息推送
一.前言 大多数系统里面好像都有获取消息的功能,但这些消息来源都不是实时的,比如你开两个浏览器,用两个不同的账号登录,用一个账号给另外一个账号发送消息,然而并不会实时收到消息,必须要自己手动F5刷新一 ...
- iOS刚进入后台接受推送、打开推送调转到相应的界面
刚进入后台的时候消息处理时候我用了本地推送!可以看我前边写的博客,怎么处理刚进入后台接收推送的案例,链接 /** 注释:打开推送的三种方式:-peter 1.apns的时候,结束进程退出后台:启动的时 ...
随机推荐
- OSharp 学习(一)
OSharp3.0 由郭明峰组织开发,已经相对比较完整,从底层代码开始阅读难度比较大. 故采用自上而下的方式,使用到的时候再完善相关功能.希望通过此教程能够找到志同道合的人. 注:请勿抄袭 请参看OS ...
- TypeScript环境搭建
环境搭建 本篇将简单介绍一下TypeScript,并记录开发环境的搭建.使用Visual Studio Code进行一个简单的Demo开发过程. 第一部分.简介 TypeScript是一种由微软开发的 ...
- Android-3 Activity启动模式
Activity启动模式 android:launchMode="singleTask" * Standard 每次都创建一个新实例 -- TaskID不变,ActivityID改 ...
- DBA 思想天空笔记
/*+leading(t1) use_nl(t2*/这个HINT的含义,其中use_nl表示强制用嵌套循环连接方式.Leading(t1)表示强制先访问t1表,也就是t1表作为驱动表,增加HINT的目 ...
- 关appid
https://code.google.com/p/goagent/wiki/InstallGuide 申请appid
- 【转】ubuntu设置PATH----不错
原文网址:http://no001.blog.51cto.com/1142339/554927 试了好多遍,多无效.. 最后在/etc/enviroment下设置才有效. 不过让有一些未解问题 我使用 ...
- SQL Interview Question
面试的时候发现会问一些SQL的基本问题,在此总结一下. ProgramInterview/SQL 这个网站上的问题还比较全. 1. Join type INNER JOIN: Returns all ...
- 【HDU1754】I Hate It(线段树)
update:单点替换 query:区间最值 #include <iostream> #include <cstring> #include <cstdlib> # ...
- 类linux 系统iptables 系统初始化配置
#!/bin/bash iptables -F iptables -X /etc/rc.d/init.d/iptables save service iptables restart iptables ...
- (转)mysql分表的3种方法
原文:http://blog.51yip.com/mysql/949.html 一,先说一下为什么要分表 当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿 ...