天道酬勤,学无止境

React Native app won't complete negotiation with SignalR Core

I'm trying to integrate the SignalR Core JS client on React Native but can't quite seem to get it to work with a ASP.NET Core server with SignalR. I've heard that other people have been able to make it work despite the lack of a designated React Native client.

I keep getting the following error: "Error: Failed to complete negotiation with the server: Error". Could someone help me?

Here's what the React Native app looks like:

App.js

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, TouchableHighlight, TextInput, Alert } from 'react-native';

import * as signalR from '@aspnet/signalr';

export default class App extends Component {

  componentDidMount() {
    let connection = new signalR.HubConnectionBuilder()
      .withUrl("http://192.168.0.89:5000/app")
      .configureLogging(signalR.LogLevel.Information)
      .build();

    connection.on("ReceiveMessage", (user, message) => {
      const msg = message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
      const encodedMsg = user + " says " + msg;
      log(encodedMsg);
    });

    connection.start().catch(err => this.logError(err));
  }

  render() {
    return (
      <View style={styles.container}>

      </View>
    );
  }

}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  }
});

Package.json

{
  "name": "TakMobile",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@aspnet/signalr": "^1.0.4",
    "react": "16.6.0-alpha.8af6728",
    "react-native": "0.57.4",
    "react-native-callkit": "^1.3.4",
    "react-native-voip-push-notification": "^1.1.2",
    "react-native-webrtc": "^1.67.1",
    "socket.io-client": "^2.1.1"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.49.0",
    "react-test-renderer": "16.6.0-alpha.8af6728"
  },
  "jest": {
    "preset": "react-native"
  }
}

Here's what the server looks like:

Startup.cs

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.Extensions.DependencyInjection;

namespace demo1
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            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();
            }

            app.UseFileServer();
            app.UseSignalR(routes =>
            {
                routes.MapHub<ApplicationHub>("/app");
            });
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace demo1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }
}

Demo1.cs project file

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

launchSettings.json

{
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://192.168.0.89:5002",
      "sslPort": 44397
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "demo1": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "http://192.168.0.89:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

ApplicationHub.cs

using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;

namespace demo1 {
    public class ApplicationHub : Hub {
        public Task Send(string message) {
            return Clients.All.SendAsync("Send", message);
        }
    }
}

评论

Turns out React Native had an issue connecting perhaps because of the https protocol. Furthermore, I also explicitly added 'Microsoft.AspNetCore.SignalR' version 1.0.4 to match the version on React Native even though it should be included in 'Microsoft.AspNetCore.App'.

So, here's the updated code that works on both React and React Native:

App.js

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, TouchableHighlight, TextInput, Alert } from 'react-native';

import * as signalR from '@aspnet/signalr';

export default class App extends Component {

  componentDidMount() {
    const hubUrl = 'http://192.168.0.89:5000/app';

const connectionHub = new signalR.HubConnectionBuilder()
  .withUrl(hubUrl)
  .configureLogging(signalR.LogLevel.Information)
  .build();

connectionHub.on('ReceiveMessage', this.messageReceived);
connectionHub.start()
  .catch(err => this.logError(err));
  }

  render() {
    return (
      <View style={styles.container}>

      </View>
    );
  }

}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  }
});

Here's what the server looks like:

Startup.cs

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.Extensions.DependencyInjection;

namespace demo1
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR();
            services.AddCors();
            services.AddMvc();
        }

        // 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();
            }
            app.UseCors(cors => {
                cors.AllowAnyHeader();
                cors.AllowAnyOrigin();
                cors.AllowAnyMethod();
                cors.AllowCredentials();
            });
            app.UseSignalR(routes =>
            {
                routes.MapHub<ApplicationHub>("/app");
            });


            app.UseHttpsRedirection();
            app.UseWebSockets();
            app.UseMvc();

        }
    }
}

Demo1.cs project file

   <Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.4" />
  </ItemGroup>

</Project>

launchSettings.json

 {
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://*:5002",
      "sslPort": 44397
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "demo1": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "http://*:5000;https://*:5001",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

As I understand, this problem is already solved, however, I thought I might share a solution to the problem I encountered (resulting in the same error message = "Error: Failed to complete negotiation with the server: Error").

The cause of my problem was that I specified a wrong port number in the client code. (as a parameter passed to HubConnectionBuilder().withUrl() method)

So instead of the "demo1"'s applicationUrl (http://192.168.0.89:5000), I needed to pass the iisExpress' applicationUrl (http://192.168.0.89:5002).

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Angular/SignalR Error: Failed to complete negotiation with the server
    Using SignalR for my server and Angular for my client... When I run my client I receive these errors: zone.js:2969 OPTIONS https://localhost:27967/chat/negotiate 0 () Utils.js:148 Error: Failed to complete negotiation with the server: Error Utils.js:148 Error: Failed to start the connection: Error I am guessing it is something with CORS... I am trying to implement a simple chat application. I am using the latest verison of SignalR: Here is the github that contains the code for the tutorial I am following. SignalR Chat Tutorial Here is my startup using Microsoft.AspNetCore.Builder; using
  • Signal R Native Android app Negotiation Failed
    I'm trying to create an android app that could connect to my basic SignalR Hub. Its just a basic Hub file i want to test things out with but I've had no luck so far. Could someone have a look at the thing(s) I'm doing wrong? Every time I try to run it I get the following stackraces: 05-27 09:10:39.785 22247-22247/nl.vict.chatapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<microsoft.aspnet.signalr.client.transport.WebsocketTransport$1> 05-27 09:10:39.785 22247-22247/nl.vict.chatapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<microsoft.aspnet
  • 在Typescript中使用ASP.NET Core SignalR和React创建实时应用程序
    目录 介绍 ScrumPoker应用程序 源代码 开发工具 基本步骤 后端代码 创建Hub 在Startup中注册集线器 创建持久性 让我们为客户端应用程序公开一些终端 启用Cors 前端代码 结论 SignalR现在包含在ASP.NET Core框架中,并且进行了大量改进,使其轻巧易用。令我惊讶的是,我找不到任何有关如何使用SignalR的好教程,并且无法使用它使相同的旧聊天应用程序变得有趣。我想到了用SignalR创建一些东西,而不是同一个无聊的聊天应用程序。 介绍 在本教程中,我将指导您完成创建实时应用程序所需的主要步骤。我不会在这里写完整的代码。您可以在github 上找到完整的源代码。 ScrumPoker应用程序 在本教程中,我们将创建一个有趣的应用程序,名为ScrumPoker。我们生活在敏捷的世界中,因此在我们的开发过程或每个冲刺周期中进行故事评估并指出要点很普遍。过去,我们曾经计划使用扑克牌,而团队则通过这些牌来进行故事评估,但是现在一切都在线上了,我们经常进行远程工作。 用户可以创建ScrumBoard链接并与队友共享链接。团队成员可以进入那里并开始指出故事。只有当创建的用户ScrumBoard允许他们查看时,团队给出的点才会显示在仪表板上。 用户会实时添加到仪表板上,他们提交的点也会实时反映出来。 源代码 ├───clientapp├───Contracts├
  • SignalR协商404(SignalR Negotiate 404)
    问题 我正在使用SignalR 2.0。 在VS 2012上本地运行时,一切正常。但是,当我在IIS上发布站点时,它会中断。 该站点已加载,但其中一个脚本返回404 Not Found。 脚本是这样的。 https://example.com/signalr/negotiate?xxx 此路径确实不存在。 正确的路径应为: https://example.com / private / signalr / negotiate?xxx 注意该部分以粗体显示。 在网站(https://example.com/)内,我有另一个应用程序(https://example.com/private/)。 这是使用SignalR。 这似乎是SignalR中的错误,因为从我的私有站点可以访问signalr / hubs路径。 回答1 我有一个类似的问题。 这是用于配置/ signalr URL的文档。 但是,我的解决方案与文档不同。 我没有更改标准的app.MapSignalR() ,而是将客户端代码更改为使用/MyApp/signalr 。 这是代码,其中“ MyApp”是我的Web应用程序的虚拟目录。 var connection = $.hubConnection('/MyApp/signalr', {useDefaultPath: false}); var changesHub =
  • asp.net core3.1 下跨域的正确方式
    作为一个上进的程序猿必须要紧跟技术。等core出来稳定后(企业招聘基本全要会core,不会混不了饭吃泪)决定要掌握core。于是在腾讯课堂花了1.1软妹币白嫖了2门课程后又在B站学习一门掌握了入门知识即可进入自学时代了。 好现在开始把学生时做的后来用其它技术改版2遍仿QQ即时聊天工具迁移到core3.1+signalr+grpc,也就是单个web有多个页面+多个web(独立网站独立部署)+桌面程序+手机APP互通聊天 不过做到第一个signalr跨域的时候就遇到了不小阻力。所以这篇就是把signalr跨域单独拿出来做一篇,(不是上面的IM开发遇到的问题的案例是遇到问题单独抽出来做个DEMO,反正也刚开始改版问题目前只遇到signalr跨域)IM的话等积累到一个阶段再发 正戏开始伟大的分割线 我的项目结构:上面是提供资源访问的signalr服务端端口5001,下面端口5000因为方便就把做grpc+signalr的DEMO拿过来了。 遇到的问题: 因为当时问题很多反复调了近3天都不得,但是当时心如死灰没心情截图bug下来。所以只好凭着程序猿自带的渣记忆还原几个问题 问题1: localhost/:1 Access to XMLHttpRequest at 'https://localhost:5001/ChatMsgCorsHub/negotiate' from origin
  • SignalR:协商请求期间出错:未定义(SignalR: Error during negotiation request: undefined)
    问题 我一直在尝试使javascript signal-r客户端与自托管的owin服务器配合工作。 并且正在遇到这个问题。 我已经尝试了两个代理并且没有代理方法,并且都具有和错误“ SignalR:协商请求期间出错:未定义”的相同结果。 我已经能够使跨域示例运行而没有任何问题,并且无法弄清楚我在做错什么,任何人有任何想法吗? 浏览器控制台获取日志以尝试协商,然后失败。 服务器/集线器 namespace SignalROwinHost { class Program { static void Main(string[] args) { string url = "http://localhost:9000/"; using (WebApplication.Start<Startup>(url)) { Console.WriteLine("Server running on {0}", url); Console.ReadLine(); } } public class Startup { public void Configuration(IAppBuilder app) { app.MapHubs(); } } public class ChatHub : Hub { public void Send(string message) { Clients.All.send
  • SignalR serverSentEvents on Windows Server 2008 with IIS 7 POST request taking too much time to complete
    I'm using SignalR 2.0.0-beta2 and it's behaving strangely in production environment where an ASP.NET MVC 5 [ .NET Framework 4.5 ] app is installed on Windows Server 2008 with IIS 7. The AppPool is in Integrated Mode and only has this app. The GET request made by SignalR takes only 60 ms: http://mysite.org.br/signalr/negotiate?clientProtocol=1.3&_=1374377239338 The problem happens with the POST request that takes forever. In the most recent test right now it took incredible 3m 1s: http://mysite.org.br/signalr/send?transport=serverSentEvents&connectionToken=Lp
  • SignalR: Error during negotiation request: undefined
    I've been trying to get a javascript signal-r client working against a self-hosted owin server. And am running into this issue. I've tried both proxies and no proxy methods both with the same result of the and error "SignalR: Error during negotiation request: undefined". I've been able to get the cross-domain sample to run without any issues and cannot figure out what I am doing wrong, anyone have any ideas? The browser console gets logs an attempt to negotiate then I get the failure. Server/Hub namespace SignalROwinHost { class Program { static void Main(string[] args) { string url = "http:/
  • 具有IIS 7 POST请求的Windows Server 2008上的SignalR serverSentEvents需要花费太多时间才能完成(SignalR serverSentEvents on Windows Server 2008 with IIS 7 POST request taking too much time to complete)
    问题 我使用的是SignalR 2.0.0-beta2,它在生产环境中的运行方式很奇怪,在生产环境中,带有IIS 7 Windows Server 2008上安装了ASP.NET MVC 5 [.NET Framework 4.5]应用程序。 AppPool处于集成模式,并且只有此应用程序。 SignalR发出的GET请求仅需60毫秒: http://mysite.org.br/signalr/negotiate?clientProtocol=1.3&_=1374377239338 该问题发生在永久性的POST请求上。 目前,在最近的测试中,它花费了不可思议的3m 1s : http://mysite.org.br/signalr/send?transport=serverSentEvents&connectionToken=Lp%2BGdI6jVTLPrQ3ZGJ065F9GrMbKYWNmgrtKPZz%2BCUYAsxrqP7hyAMPr%2Bg1E3IRY%2F0brzXVanumPy7NPCFOlcXTRrJssFD2EEoxd6fWhAVEUSfIj 发生此间歇性问题时,通常需要40秒钟以上才能完成请求。 使用Firefox 22和Firebug对其进行测试...如果禁用浏览器缓存,它将流畅运行,也就是说,它不会延迟POST请求。 否则,当我启用浏览器缓存时
  • MVC5 hangs on MapSignalR when reconnecting after AppPool cycles
    I have the following code in my Startup.SignalR.cs: using Microsoft.AspNet.SignalR; using Owin; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Admin { public partial class Startup { public void ConfigureSignalR(IAppBuilder app) { var Config = new HubConfiguration() { EnableDetailedErrors = false, Resolver = new DefaultDependencyResolver() }; #if DEBUG Config.EnableDetailedErrors = true; #endif // Any connection or hub wire up and configuration should go here app.MapSignalR(); GlobalHost.Configuration
  • SignalR应用程序无法在IIS下运行(SignalR applications do not work under IIS)
    问题 我试图在Visual Studio 2012中构建SignalR应用程序。我的问题是,它在Visual Studio调试下(在Windows 7上使用Visual Studio 2012)运行良好,但是当我尝试在Windows Server 2012上的IIS 8上部署该应用程序时,该应用程序只显示了index.html页面。 我决定尝试缩小问题范围,无论是在我的代码中还是在SignalR中。 我编译了http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr中显示的SignalR教程。 在Visual Studio上这可以正常工作,但是除了在IIS下显示静态页面外,它不会做任何其他事情。 我尝试了这里列出的一些方法:Signalr / Hub在IIS 7中未加载,但在Visual Studio中正常运行,但似乎都无法正常工作。 回答1 假设您实际上想要查看index.html (即您的问题不是“显示的是空的index.html而不是我的聊天页面chat.html”),那么听起来就像当您在聊天页面中输入内容时,并不是在连接到该聊天的其他浏览器窗口中显示为聊天。 我会尝试一些基本测试。 我将假设: 在服务器上安装并配置了ASP.NET(如果没有,请参见脚注)
  • Cross origin SignalR connection stops after negotiate
    I have an MVC 5 app serving up views, and a Web API 2 app as the service layer (.NET 4.5). The Web API app uses SignalR 2.1.2 to return progress as it's processing POSTs to the service API. The two are deployed to different domains, so I've set up cross origin support as per the asp.net tutorial article. [assembly: OwinStartup(typeof (Startup))] namespace MyApp.Service { public class Startup { public void Configuration(IAppBuilder app) { app.Map("/signalr", map => { //worry about locking it down to specific origin later map.UseCors(CorsOptions.AllowAll); map.RunSignalR(new HubConfiguration())
  • Angular : Unable to pass API url in SignalR HubConnection
    I have developed a project in Angular6. There is a requirement to develop section for live chat. For that I am using SignalR in my asp.net core Web Apiproject. Now I want to use this Web Api reference in my Angular project. I am using this link. But while providing the Web Api url in App.Component.ts, I am getting below error : Constructor of class 'HubConnection' is private and only accessible within the class declaration. App Component.ts : import { HubConnection } from '@aspnet/signalr'; import { Message } from 'primeng/api'; export class AppComponent implements OnInit { public
  • .NET Framework 4.6,.Net Native和.Net Core之间的区别(Difference between .NET Framework 4.6, .Net Native and .Net Core [closed])
    问题 关门了。 这个问题需要更加集中。 它当前不接受答案。 想要改善这个问题吗? 更新问题,使其仅通过编辑此帖子即可将重点放在一个问题上。 2年前关闭。 改善这个问题 在以后的几乎每个.NET框架讨论中,我都会看到以下内容: .NET Framework 4.6(完整的.Net Framework) .NET本机 .NET核心 所有这些之间有什么区别? 我怎么知道什么时候使用合适的呢? 回答1 浏览了各种链接和视频后,我发现了一个整体有趣的图片: 根据以上内容,我们可以轻松推断出以下内容: .NET Framework 4.6是适用于与.NET相关的所有内容的完整框架,但缺少针对多平台(Windows,Linux和Mac)和云部署进行了优化的库和运行时。 另一方面, .NET Core是.NET Framework 4.6的子集,主要针对多平台和云部署进行了优化。 .NET Native主要用于开发通用应用程序,该应用程序将经过优化,可在任何设备和平台上本地运行(尽管不适用于Web应用程序) 有趣的一点是ASP.NET: 如果我们需要最大程度的向后兼容性(例如Web表单或aspx支持),则需要使用.NET Framework 4.6 如果我们开发MVC,Web API或Razor网页,则可以在.NET Framework 4.6或.NET Core环境中部署这些Web应用程序
  • AspNetCore.SignalR 2.1 and CORS
    I'm migrating our SignalR-Service to the new AspNetCore.SignalR (2.1 preview) and now I get problems with CORS. I will never access the service from the same origin, so I need to disable CORS in general. I have the folowing CORS policy services.AddCors( options => options.AddPolicy("AllowCors", builder => { builder .AllowAnyOrigin() .AllowCredentials() .AllowAnyHeader() .AllowAnyMethod(); }) ); (My WebApi-Controller calls from a different origin are working fine with these policy) With the old preview package of SignalR for AspNetCore (AspNetCore.SignalR.Server) I don't got any problems but
  • Where to put SignalR hub in React/Redux app?
    I'm designing a React website using Redux as the state store, which is primarily to display the current population of items to the user, using live updates to update the item population using SignalR. The way I wanted to do this was to have SignalR send item update messages both to initialise the starting population when you connect to the server hub, as well as updates via the same message type as time goes on. I would have a function that takes a SignalR message and converts it to a Redux action and dispatches to Redux store, which would then use the action to update the state and then the
  • SignalR cross-domain connections with self-hosting and authentication
    I have a CORS problem when self-hosting SignalR with OWIN, which only happens when I try to enable authentication. The error I get in my web browser is: XMLHttpRequest cannot load http://.../signalr/negotiate?[snip] Origin ... is not allowed by Access-Control-Allow-Origin This only happens if I enable authentication in my self-hosted server using the approach in this answer: public void Configuration(IAppBuilder app) { var listener = (HttpListener)app.Properties[typeof(HttpListener).FullName]; listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm; app.MapHubs(new HubConfiguration {
  • 从控制器调用 SignalR Core Hub 方法(Call SignalR Core Hub method from Controller)
    问题 如何从 Controller 调用 SignalR Core Hub 方法? 我将 ASP.NET Core 2.0 与 Microsoft.AspNetCore.SignalR (1.0.0-alpha2-final) 一起使用。 我有与 Excel、SolidEdge 通信的 Windows 服务......操作完成后,它会在 ASP.NET Core 应用程序中向我的控制器发送请求。 现在我需要用 SignalR 通知所有连接到服务器的客户端外部程序完成了一些任务。 我无法改变窗口服务的工作方式。 (无法从窗口服务连接到 SignalR)。 我发现老SignalR(大量的解决方案GlobalHost.ConnectionManager.GetHubContext ),但大部分已经改变,这些解决方案都不能工作了。 我的控制器: [Route("API/vardesigncomm")] public class VarDesignCommController : Controller { [HttpPut("ProcessVarDesignCommResponse/{id}")] public async Task<IActionResult> ProcessVarDesignCommResponse(int id) { //call method
  • 具有自托管和身份验证的 SignalR 跨域连接(SignalR cross-domain connections with self-hosting and authentication)
    问题 使用 OWIN 自托管 SignalR 时,我遇到了 CORS 问题,这仅在我尝试启用身份验证时发生。 我在网络浏览器中遇到的错误是: XMLHttpRequest 无法加载 http://.../signalr/negotiate?[snip] Origin ... is not allowed by Access-Control-Allow-Origin 仅当我使用此答案中的方法在自托管服务器中启用身份验证时才会发生这种情况: public void Configuration(IAppBuilder app) { var listener = (HttpListener)app.Properties[typeof(HttpListener).FullName]; listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm; app.MapHubs(new HubConfiguration { EnableCrossDomain = true }); } 如果我注释掉AuthenticationSchemes行,那么 CORS 就可以工作(并且我已经检查了这些说明中的所有内容)。 如果我使用 NTLM 以外的其他身份验证方案,我会遇到同样的问题。 使用 Fiddler 检查发生了什么,没有启用身份验证
  • Silverlight, SignalR and IIS Applications off of the Default Web Site
    I'm using SignalR in a Silverlight 5 application. When I host my app in an "application" off of the default website in IIS 7.5 (i.e. localhost/subsite) Fiddler shows I get a 404 for "/signalr/negotiate". It doesn't seem to take the IIS application path into account. It should be requesting "/subsite/signalr/negotiate". How do I get it to use the correct url prefix? Update: I had to use the following code because it seems to be difficult to get the real root URI in a silverlight app without doing some parsing. string xapLocationUri = Application.Current.Host.Source.AbsoluteUri; string rootUri =