小编hal*_*r73的帖子

跨域不适用于SignalR PersistentConnection

注意:其他人最初问过这个问题,但在我发布答案之前删除了它.由于这个问题涵盖了开发人员在尝试使SignalR跨域工作时遇到的许多问题,因此我决定复制它.另外,我已经写完了答案!

我在ASP.NET MVC .NET Framework 4项目中运行SignalR 1.0.1服务器.我在另一个域(不同的localhost端口)上尝试通过JavaScript客户端连接另一个ASP.NET应用程序.当我的应用程序尝试连接时,我得到了这个:

XMLHttpRequest cannot load http://localhost:31865/api/negotiate?_=1363105027533.
Origin http://localhost:64296 is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)

我已经按照所有步骤启用SignalR的跨域支持 - 我缺少什么?

  • jQuery.support.cors = true;
  • $.connection('http://localhost:31865/api', '', false, { jsonp: true, xdomain: true });
  • RouteTable.Routes.MapHubs(new HubConfiguration { EnableCrossDomain = true });
  • RouteTable.Routes.MapConnection<ApiConnection>("/api", "api");

我还在API项目的Web.config中添加了以下内容:

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
    </customHeaders>
  </httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

我正在为我的SignalR服务器使用PersistentConnection,而不是集线器.

有任何想法吗?

javascript asp.net-mvc cross-domain signalr signalr.client

14
推荐指数
1
解决办法
8064
查看次数

给定一个ContainerBuilder,我可以注册一个缺少的依赖处理程序吗?

我正在尝试使用以下签名创建一个方法:

void Chain(ContainerBuilder builder, IServiceProvider fallbackServiceProvider)
{
   // ...
}
Run Code Online (Sandbox Code Playgroud)

这个想法是Chain可以使用如下:

IServiceProvider fallbackProvider = someExternalProvider;
var builder = new ContainerBuilder();

// Custom registration might happen before and/or after the call to Chain
builder.Register<MyCustomService>().As<IMyCustomService>();
builder.Register<MyExternalServiceReplacement>.As<IExternalService>();

Chain(builder, someExternalProvider);

IContainer container = builder.Build();

// customService should be a MyCustomService
var customService = container.Resolve<IMyCustomService>();

// replacedService should be overridden by MyExternalServiceReplacement
// even though an IExternalService also exists in someExternalProvider
var replacedService = container.Resolve<IExternalService>();

// nonReplacedService should come from someExternalProvider since
// …
Run Code Online (Sandbox Code Playgroud)

c# autofac

9
推荐指数
1
解决办法
1644
查看次数

SignalR HubConnection无效的URI

根据我发现的一个例子,http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service,我在Windows中实现了一个SignalR主机服务器服务.

一切正常,但如果我尝试:

SignalR = WebApp.Start<SignalRStartup>("http://*:8080/");
Run Code Online (Sandbox Code Playgroud)

我得到一个未处理的类型`异常

'System.UriFormatException'` occurred in System.dll

Additional information: Invalid URI: The hostname could not be parsed.
Run Code Online (Sandbox Code Playgroud)

如果我使用,它工作正常

SignalR = WebApp.Start<SignalRStartup>("http://localhost:8080/");
Run Code Online (Sandbox Code Playgroud)

可能是一个愚蠢的假设,但基于我从中得到的文章,我假设*:8080语法可行.我的问题是,如果我错过了某些内容或文章不正确,这种格式不起作用?

c# signalr owin

5
推荐指数
1
解决办法
1948
查看次数