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的时候,结束进程退出后台:启动的时 ...
随机推荐
- table行转列
table行转列 摘要 在使用ews调用exhange的收件箱的并在h5页面显示邮件详情的时候,因为返回的每封邮件的内容都是htmlbody,没有textbody.每封邮件又没什么规律,用正则表达式来 ...
- Core Data的使用(二)备
一.基础概念深入 1.NSManagedObjectContext 被管理数据上下文就像便笺簿 当从数据持久层获取数据时,相当于把这些临时的数据拷贝写在便笺簿上,然后就可以随心所欲的修改这些值. 通过 ...
- win7 x64 jdk1.7.0_51
1:我的 jdk与jre默认安装在:D:\Program Files\Java 2:配置环境变量(系统变量): (1)新建JAVA_HOME (2)新建CLASSPATH (3)编辑Path,%JAV ...
- Codeforces 245H Queries for Number of Palindromes
http://codeforces.com/contest/245/problem/H 题意:给定一个字符串,每次给个区间,求区间内有几个回文串(n<=5000) 思路:设定pd[i][j]代表 ...
- Android添加横线和竖线分割界面
竖线 <View android:layout_width="1dip" android:layout_height="match_parent ...
- php安装pear、pecl
安装pear.pecl特别简单,只需要两步. wget http://pear.php.net/go-pear.phar php go-pear.phar [root@localhost bin]# ...
- cf448B Suffix Structures
B. Suffix Structures time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Inorder Successor in BST 解答
Question Given a binary search tree and a node in it, find the in-order successor of that node in th ...
- Java学习作业(14.4.21)
前三次作业都是基础语法.真的好水啊.从这次开始记录. 1.编写Java程序,把当前目录下扩展名为txt的文件的扩展名全部更名为back. import java.io.*; import java.l ...
- OpenWrt opkg 在线源默认配置
dest root /dest ram /tmplists_dir ext /var/opkg-listsoption overlay_root /overlaysrc/gz barrier_brea ...