我正在尝试将SignalR添加到我的项目中(ASPNET MVC 4).但我不能让它发挥作用.
在下图中,您可以看到我收到的错误.
我已经阅读了很多stackoverflow帖子,但没有一个是解决我的问题.
这是我到目前为止所做的:
1) Ran Install-Package Microsoft.AspNet.SignalR -Pre
2) Added RouteTable.Routes.MapHubs(); in Global.asax.cs Application_Start()
3) If I go to http://localhost:9096/Gdp.IServer.Web/signalr/hubs I can see the file content
4) Added <modules runAllManagedModulesForAllRequests="true"/> to Web.Config
5) Created folder Hubs in the root of the MVC application
6) Moved jquery and signalR scripts to /Scripts/lib folder (I'm not using jquery 1.6.4, I'm using the latest)
Run Code Online (Sandbox Code Playgroud)
这是我的Index.cshtml
<h2>List of Messages</h2>
<div class="container">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="Send" />
<input …
Run Code Online (Sandbox Code Playgroud) 有没有办法找出侦听器的数量(连接到集线器的客户端?)
如果至少连接了一个客户端,我正在尝试运行/启动任务,否则不启动它:
[HubName("taskActionStatus")]
public class TaskActionStatus : Hub, IDisconnect
{
static CancellationTokenSource tokenSource;
public void GetTasksStatus(int? siteId)
{
tokenSource = new CancellationTokenSource();
CancellationToken ct = tokenSource.Token;
ITaskRepository taskRepository = UnityContainerSetup.Container.Resolve<ITaskRepository>();
// init task for checking task statuses
var tasksItem = new DownloadTaskItem();
taskRepository.GetTasksStatusAsync(siteId, tasksItem, ct);
// subscribe to event [ listener ]
tasksItem.Changed += new EventHandler<TaskEventArgs>(UpdateTasksStatus);
}
public void UpdateTasksStatus(object sender, TaskEventArgs e)
{
Clients.updateMessages(e.Tasks);
}
// when browsing away from page
public Task Disconnect()
{
try
{
tokenSource.Cancel();
} …
Run Code Online (Sandbox Code Playgroud) 如何从控制器的操作中调用hub方法?这样做的正确方法是什么?
有人在帖子中使用过这个:
DefaultHubManager hd = new DefaultHubManager(GlobalHost.DependencyResolver);
var hub = hd.ResolveHub("AdminHub") as AdminHub;
hub.SendMessage("woohoo");
Run Code Online (Sandbox Code Playgroud)
但对我来说,这是投掷:
不支持使用不是由HubPipeline创建的Hub实例.
我还读到你可以创建一个集线器上下文,但我不想对这个动作负责,也就是说,动作做的事情如下:
hubContext.Client(...).someJsMethod(..)
Run Code Online (Sandbox Code Playgroud) 我正在逐步学习本教程
而且我在下面标出的行上有例外
string url = "http://localhost:8080";
using (WebApp.Start(url)) //<------ error on this line
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
无法加载文件或程序集"Microsoft.Owin.Security,Version = 2.0.1.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
更多信息:
在我的项目解决方案中,引用指向NuGet的packages文件夹中的dll
这已由NuGet添加到我的App.config文件中
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
Run Code Online (Sandbox Code Playgroud)
在packages文件夹中,packages\Microsoft.Owin.Security.2.0.0\lib\net45
Microsoft.Owin.Security.dll的文件版本为2.020911.395
有时在使用IISExpress在VS2012中运行我的MVC4站点时,我收到以下错误并且IISExpress停止:
iisexpress.exe: Managed (v4.0.30319)' has exited with code -1073741816 (0xc0000008) 'An invalid handle was specified
Run Code Online (Sandbox Code Playgroud)
事件日志中没有任何内容,我无法在interweb上找到任何内容.
我有一些非常含糊的理论:
哦,我在使用VS Dev Web服务器时也遇到了同样的错误.我还没试过完整的IIS.
别人都有线索?
谢谢
更新:
我修了几个nuget参考文献,似乎有点稳定,然后今天早上又发生了.VS输出窗口显示:
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Mobile\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\peter.jones\AppData\Local\Temp\Temporary ASP.NET Files\root\a4aa93f7\dfa23a50\App_Web_rpzlbjhw.dll', Symbols loaded.
'iisexpress.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\peter.jones\AppData\Local\Temp\Temporary ASP.NET Files\root\a4aa93f7\dfa23a50\App_Web_c1rjct4s.dll', Symbols loaded.
The program '[11072] iisexpress.exe: Managed (v4.0.30319)' has exited with code -1073741816 (0xc0000008) 'An invalid handle was …
Run Code Online (Sandbox Code Playgroud) 我需要获取客户端的连接ID.我知道你可以从客户端使用它$.connection.hub.id
.我需要的是在我拥有的Web服务中进入更新数据库中的记录,然后在网页上显示更新.我是signalR和stackoverflow的新手,所以任何建议都会受到赞赏.在我的客户端网页上,我有这个:
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var notify = $.connection.notificationHub;
// Create a function that the hub can call to broadcast messages.
notify.client.broadcastMessage = function (message) {
var encodedMsg = $('<div />').text(message).html();// Html encode display message.
$('#notificationMessageDisplay').append(encodedMsg);// Add the message to the page.
};//end broadcastMessage
// Start the connection.
$.connection.hub.start().done(function () {
$('#btnUpdate').click(function () {
//call showNotification method on hub
notify.server.showNotification($.connection.hub.id, "TEST status");
});
});
});//End Main function
</script>
Run Code Online (Sandbox Code Playgroud)
一切正常,直到我想使用signalR更新页面.我的集线器中的显示通知功能是这样的: …
我过去几天一直在关注SignalR.使用这个我创建了一个Admin Dashboard来获取有关数据库表的实时信息.基本上,这个表可以填充来自不同应用程序的不同用户.它表现得很好.只有在客户端Broswer和WebServer之间存在持久连接时,才可以进行这些更新.在生产中部署此应用程序之前,我几乎没有疑问.
据我所知,SignalR首先检查WebSockets,然后根据客户端和服务器之间的可用性查找长轮询.无论使用什么,客户端和服务器之间都会建立连接.
我的问题是它是如何在更多用户连接到同一服务器的情况下执行的,例如同时连接100,000个管理员.IIS是否可以在一次打开的持久连接数量上有任何限制?如果是这样,我们可以将其配置为最大值以及该值是什么.
对不起,如果是菜鸟问题
ASP.NET MVC3和IIS 7用于开发.
SignalR和Reactive Extensions一样吗?你能解释为什么或为什么不解释?
这让我疯了.
我正在使用最新的signalR版本(2.0.2).这是我的集线器代码(OnConnected)
public override Task OnConnected()
{
//User is null then Identity and Name too.
Connections.Add(Context.User.Identity.Name, Context.ConnectionId);
return base.OnConnected();
}
Run Code Online (Sandbox Code Playgroud)
这是我的Controller的登录方法:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UnitOfWork.UserRepository.FindAsync(model.UserName, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
}
TempData["ErrorMessage"] = Resources.InvalidUserNameOrPassword;
// If we got this far, something failed, redisplay form
return RedirectToAction("Index","Home");
}
Run Code Online (Sandbox Code Playgroud)
我发现有些人在OnDisconnected上遇到这个问题,我甚至都没有.
我正在使用MCV5模板.
你知道什么是错的吗?
自从更新到VS2013后,我们在运行我们的(MCV4)Web应用程序时收到此错误:
The controller for path '/9ac086a69364466a841e03e001f946fd/arterySignalR/ping' could not be found.
Run Code Online (Sandbox Code Playgroud)
我知道它与浏览器链接有关,虽然我不确定我们需要做些什么来使其正常工作.我们需要进行一些配置更改才能支持这项新功能吗?
signalr ×10
asp.net-mvc ×5
c# ×4
signalr-hub ×4
asp.net ×2
.net ×1
iis ×1
iis-express ×1
mef ×1
owin ×1