我遇到了允许SignalR持续连接的所有来源的问题。似乎,称为“UseCors”没有效果。端点初始化过程(与CORS相关的设置)如下:
app.Map("/myendpoint", map =>
{
map.UseCors(CorsOptions.AllowAll).RunSignalR<MyEndPoint>();
});
尝试从远程计算机上的js代码建立连接仍然会导致请求的资源上出现“No'Access-Control-Allow-Origin'标头。”我做错了什么,有没有办法允许CROSS-ORIGIN请求?
答案 0 :(得分:0)
在启动时
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.Owin.Cors;
[assembly: OwinStartup(typeof(Werp.Wacc.Web.API.Startup))]
namespace YourApplication.API
{
public class Startup
{
/// <summary>
///Configure Signal R
/// </summary>
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
app.UseCors(CorsOptions.AllowAll);
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}