我正在尝试从.NET CORE 2.1后端上的本地SignalR服务更改为Azure SignalR。
全部:v1.0.4中的Angular(@ aspnet / signalr),SignalR和Azure SignalR软件包。
在本地配置下,一切正常。
services.AddCors(options =>
{
options.AddPolicy("AllowAll", builder =>
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
services.AddMvc(options =>
{
//options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
options.Filters.Add(new RequireHttpsAttribute());
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddJsonOptions(options =>
{
//options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
services.AddSignalR(hubOptions =>
{
hubOptions.EnableDetailedErrors = true;
});
和
app.UseCors("AllowAll");
app.UseSignalR(routes =>
{
routes.MapHub<SomeHub>("/ws/somehub");
});
更改后:
services.AddSignalR().AddAzureSignalR(Configuration["AzureSignalRConnectionString"]);
app.UseAzureSignalR(routes =>
{
routes.MapHub<SomeHub>("/ws/somehub");
});
我在谈判中的建议是:
选项后为204
开机自检后404
URL是正确的,以HTTPS开头,以'ws / somehub / negotiate'结束
答案 0 :(得分:0)
首先注释CORSPolicy
中与Startup.cs
相关的代码,然后尝试
在您的Startup.cs
对于Configure
方法
app.UseCors(builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.WithMethods("GET", "POST")
.AllowCredentials();
});