- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经研究这个问题 3 天了,但找不到解决方案。我使用以下代码创建了一个 SignalR Hub:
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
namespace Messenger.Hubs
{
public class MessengerHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
}
很简单,启动代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Messenger.Hubs;
namespace Messenger
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("c:/myapp/Messenger");
});
app.UseMvc();
}
}
}
我几乎从互联网上某个地方发布的解决方案中剪切并粘贴了代码,但我忘记了在哪里,虽然不是 stackoverflow。然后,我使用 Visual Studio 2017 (v15.9.10) 在 Xamarin (v4.12.3.81) 项目中创建了以下客户端。该代码是:
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;
namespace SignalR.Client.Hubs
{
public class SampleHub
{
// MessengerHub is a appliaction folder aliased as MessengerHub
// the direct path on the machine is c:\mywebapp\messenger
private const string _hubUrl = "http://example.com/MessengerHub";
private readonly HubConnection _hubConnection;
public event EventHandler<string> OnMessageReceived;
public SampleHub()
{
var builder = new HubConnectionBuilder().WithUrl(_hubUrl);
_hubConnection = builder.Build();
}
public async Task<bool> ConnectAsync()
{
try
{
await _hubConnection.StartAsync();
_hubConnection.On("messageReceived", (string platform, string message) =>
{
if (OnMessageReceived != null)
{
OnMessageReceived(this, string.Format("{0}: {1}", platform, message));
}
});
}
catch (Exception ex)
{
var msg = ex.Message;
//Console.WriteLine($"Connection error: {ex.Message}");
return false;
}
return true;
}
public async Task<int> GetNumberAsync(int number)
{
return await _hubConnection.InvokeAsync<int>("GetNumber", number);
}
public Task Send(string message)
{
return _hubConnection.SendAsync("Send", message);
}
}
}
事件中使用该客户端的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Views.InputMethods;
using SignalR.Client.Hubs;
namespace MyXamarinApp
{
[Activity(Label = "Messenger")]
public class Messenger : Activity
{
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.Messenger);
RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
try
{
var input = FindViewById<EditText>(Resource.Id.Input);
var messages = FindViewById<ListView>(Resource.Id.Messages);
var inputManager = (InputMethodManager)GetSystemService(InputMethodService);
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, new List<string>());
messages.Adapter = adapter;
var hub = new SampleHub();
await hub.ConnectAsync(); // <---- fails here
input.EditorAction +=
delegate
{
inputManager.HideSoftInputFromWindow(input.WindowToken, HideSoftInputFlags.None);
if (string.IsNullOrEmpty(input.Text))
return;
hub.Send(input.Text);
input.Text = "";
};
hub.OnMessageReceived +=
(sender, message) => RunOnUiThread(() =>
adapter.Add(message));
}
catch (Exception ex)
{
var msg = ex.Message;
}
}
}
}
集线器(我相信)在服务器上正常运行,我设置了登录,这是日志中的内容:
Hosting environment: Production
Content root path: C:\mywebapp\Messenger
Application started. Press Ctrl+C to shut down.
尝试连接到集线器会产生以下错误:
{System.Net.Http.HttpRequestException: 404 (Not Found)
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode () [0x0002a] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0
at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection+<NegotiateAsync>d__44.MoveNext () [0x00226] in <843c441fa9954906b53e3710152bebb9>:0
--- End of stack trace from previous location where exception was thrown
--- at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection+<GetNegotiationResponseAsync>d__51.MoveNext () [0x00077] in <843c441fa9954906b53e3710152bebb9>:0
--- End of stack trace from previous location where exception was thrown
---
at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection+<SelectAndStartTransport>d__43.MoveNext () [0x00169] in <843c441fa9954906b53e3710152bebb9>:0
--- End of stack trace from previous location where exception was thrown
---
at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection+<StartAsyncCore>d__40.MoveNext () [0x00118] in <843c441fa9954906b53e3710152bebb9>:0
--- End of stack trace from previous location where exception was thrown
--- at System.Threading.Tasks.ForceAsyncAwaiter.GetResult () [0x0000c] in <843c441fa9954906b53e3710152bebb9>:0
at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection+<StartAsync>d__39.MoveNext () [0x0008b] in <843c441fa9954906b53e3710152bebb9>:0
--- End of stack trace from previous location where exception was thrown
--- at Microsoft.AspNetCore.SignalR.Client.HttpConnectionFactory+<ConnectAsync>d__3.MoveNext () [0x0009d] in <d50de232736c4c8f910083ea0cb358a8>:0
--- End of stack trace from previous location where exception was thrown
---
at Microsoft.AspNetCore.SignalR.Client.HttpConnectionFactory+<ConnectAsync>d__3.MoveNext () [0x00142] in <d50de232736c4c8f910083ea0cb358a8>:0
--- End of stack trace from previous location where exception was thrown
---
at Microsoft.AspNetCore.SignalR.Client.HubConnection+<StartAsyncCore>d__47.MoveNext () [0x00130] in <f381011e9b214489bcb373743f31ed9d>:0
--- End of stack trace from previous location where exception was thrown
---
at System.Threading.Tasks.ForceAsyncAwaiter.GetResult () [0x0000c] in <f381011e9b214489bcb373743f31ed9d>:0
at Microsoft.AspNetCore.SignalR.Client.HubConnection+<StartAsync>d__39.MoveNext () [0x00091] in <f381011e9b214489bcb373743f31ed9d>:0
--- End of stack trace from previous location where exception was thrown
---
at SignalR.Client.Hubs.SampleHub+<ConnectAsync>d__6.MoveNext () [0x00037] in C:\Users\<username>\Documents\Visual Studio 2017\Projects\signalr_client\signalr_client\Resources\layout\Client.cs:28 }
这是我在网站的 IIS 日志中看到的内容。
"POST /MessengerHub/negotiate HTTP/1.1" 303 446
"GET /MessengerHub/negotiate HTTP/1.1" 404 1509
我不知道接下来要尝试什么。
最佳答案
我今天遇到了这个错误,在浪费了一些时间之后我忘记了添加:
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<FooHub>("/FooHub");
});
到我的 .NET 5 ASP.NET 应用程序中的 Startup.cs >> public void Configure(...)。
自从最初发布以来,情况发生了一些变化(我确实看到了一些 Xamarin),但希望这能在未来为某人提供一些指导。
关于c# - 与 SignalR Hub 的连接失败并显示协商 404(未找到),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55403257/
这是 Controller 方法,它接收应该被踢出的userName。 public ActionResult Kick(string userName) { var h
ASP.NET SignalR Hubs API 指南 - 服务器 ( https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-
我知道程序以及如何从 GitHub 或 BitBucket 配置自动化 docker hub。 但是我现在要做的是创建两个名为 Test/main 的 docker hub 存储库。和 Test/de
这是场景: Device1同时发送两条iothub D2C消息: 这会将标志设置为 true 这会将标志设置为 false 物联网消息路由将消息路由到 eventhub,这将触发 EventHubTr
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我是 selenium 的新手,我一直在尝试启动 Selenium Hub 并使用 java 将节点添加到 Hub。我已使用命令提示符启动它,但我希望它自行发生。我能够启动 Hub,但不知道如何添加节
我正在使用 SignalR 项目,我想在 WebApi 项目和 Web 项目中使用 Hub。所以我创建了一个类库项目并在那里实现了 Hub。 我的项目结构如下: -ChatHub -Hub -We
在开始之前,我想提一下,这并不完全是重复的,其他类似的问题对我的情况没有任何有用的答案。 在我的 ASP.Net Core 2.1 中,我有一个可以使用 AJAX 调用的操作(它的名称是 Create
我得到以下堆栈跟踪: { “状态”:13 “值(value)”: { “class”:“java.lang.NullPointerException”, “堆栈跟踪”: [ { “fileName”:
这是我当前的设置: 从 Bitbucket 获取存储库 使用 Amazon Linux 2 AWS 托管镜像构建 docker 镜像 将图像推送到 ECR 我现在有时会在 docker 构建阶段收到
我开发了一个 PDF Converter / Viewer for Windows Phone 7 , 但除非它可以从某处获取源文件(Word、Excel、PowerPoint 等),否则它毫无用处。
在 ASP.Net MVC 5 项目的根目录中创建 SignalR 2 Hub 类工作得很好。您可以访问 ~/signalr/hubs url 并返回代理。您还可以将该类放在名为 Hubs 或类似名称
我正在从我的工作站测试 ML DHF Quickstart Hub,并且可以很好地连接到 MarkLogic 的本地实例。但是当我创建一个新的环境 gradle-DEV.properties 文件并尝
我想监视来 self 的应用程序的一些事件。 一种选择是将数据发送到 Azure 事件中心并使用流分析进行一些后处理并将数据输入到 cosmos db 中。 另一个选项是从应用程序存储到 cosmos
我想监视来 self 的应用程序的一些事件。 一种选择是将数据发送到 Azure 事件中心并使用流分析进行一些后处理并将数据输入到 cosmos db 中。 另一个选项是从应用程序存储到 cosmos
(我是 Signalr 新手) 我正在开发一个 Web 应用程序,它使用 Signalr-core 来实时更新页面。 我遇到的问题是,当我运行多个客户端时,我正在运行的方法将同时运行与客户端数量一样多
我是 SignalR 库的新手。我在 VS2010 中创建了一个新的 Web 项目,然后在包管理器控制台中我执行了以下命令来设置 SignalR 包。 PM> Install-Package Micr
我将我的Docker镜像标记为foo/foo:latest 当只有一张图片时,可以做docker push 但是由于我总是将它们标记为foo/foo:latest,所以我想知道是否可以上传不是最新生成
我有一个容器,我想对其进行更改。 它托管在docker hub上,我想更改其命令之一以安装其他应用程序。 我可以在docker hub中看到各个步骤,但不能看到dockerfile本身(不确定原因)。
我正在尝试找到一种方法,可以在短时间内将100幅图像推送到Docker集线器。有没有更好,更有效的方法来做到这一点? alpine:1.0.0.0 alpine:2.0.0.0 . .. ... al
我是一名优秀的程序员,十分优秀!