Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

SignalR Javascript client CORS issue 'Access-Control-Allow-Origin' header in the response must not be the wildcard #2095

@davenewza

Description

@davenewza

I are unable to connect to our SignalR hub, hosted on Azure App Service, using the JavaScript client found here: https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-2.1

Failed to load https://myapp.azurewebsites.net/location/negotiate: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'null' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Startup.cs looks something like this:

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
        {
            builder
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin()
                .AllowCredentials();
        }));

        services
            .AddMvcCore()
            .AddJsonFormatters();

        services.AddSignalR();

        var provider = services.BuildServiceProvider();
        return provider;
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseCors("CorsPolicy");

        app.UseMvc();

        app.UseSignalR(routes =>
        {
            routes.MapHub<LocationsHub>("/location");
        });
    }

I am using the latest 2.1.0-preview2-final libraries.

Allowed origins is set to "*" in the Web App and websockets are enabled:

image

I am able to connect just fine to this hub using the C# client.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions