title: How to work with SignalR in ASP.NET Core 3.0
body: <p>We're working on an asp.net core project that depends on SignalR. Lastly we updated our project from ASP.NET Core 2.2 to 3.0 and SignalR stopped working. In the documentation we configured everything (I think correctly) but is still doesn't work. What did we miss?</p>
  <p><strong>ASP.NET Core 3.0 API</strong></p>
  <p>Startup:</p>
  <pre><code>public class Startup
  {
       private readonly string corsPolicy = &quot;CorsPolicy&quot;;
       private static string[] AllowdOrigins() =&gt; return new string[] {&quot;localhost:4200&quot;,&quot;example.com&quot;};
  
       public Startup(IConfiguration configuration)
       {
           Configuration = configuration;
       }
  
       public IConfiguration Configuration { get; }
  
       public void ConfigureServices(IServiceCollection services)
       {
              ConfigureAuthentication(services);
  
              ///MICROSOFT SQL DATABASE
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                  options.UseSqlServer(
                      Configuration.GetConnectionString(&quot;DefaultConnection&quot;)
              ));
  
              services.Configure&lt;ApiBehaviorOptions&gt;(options =&gt;
              {
                  options.SuppressModelStateInvalidFilter = true;
              });
  
              services.Configure&lt;ForwardedHeadersOptions&gt;(options =&gt;
              {
                  options.KnownProxies.Add(IPAddress.Parse(&quot;XX.XX.XX.XX&quot;));
              });
  
              services.AddSignalR();
              services.AddControllers();
  
              //services dependencies
          }
  
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseHttpsRedirection();
              app.UseRouting();
              app.UseCors(corsPolicy);
  
              //app.UseForwardedHeaders(new ForwardedHeadersOptions
              //{
              //    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
              //});
  
              app.UseAuthentication();
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
                  endpoints.MapHub&lt;ChatHub&gt;(&quot;/chat&quot;);
              });
  
              DummyData.Initialize(app);
          }
  
          private void ConfigureAuthentication(IServiceCollection services)
          {
              services.AddCors(options =&gt;
              {
                  options.AddPolicy(corsPolicy,
                  builder =&gt;
                  {
                      builder
                      .AllowAnyMethod()
                      .AllowAnyHeader()
                      .AllowAnyOrigin()
                      .AllowCredentials()
                      .WithOrigins(AllowdOrigins());
                  });
              });
  
              services.AddHttpContextAccessor();
  
              // configure strongly typed settings objects
              var appSettingsSection = Configuration.GetSection(&quot;AppSettings&quot;);
              services.Configure&lt;AppSettings&gt;(appSettingsSection);
  
              // configure jwt authentication
              var appSettings = appSettingsSection.Get&lt;AppSettings&gt;();
              var key = Encoding.ASCII.GetBytes(appSettings.Secret);
  
              services.AddAuthentication(x =&gt;
              {
                  x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                  x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
              })
              .AddJwtBearer(x =&gt;
              {
                  x.RequireHttpsMetadata = false;
                  x.SaveToken = true;
                  x.TokenValidationParameters = new TokenValidationParameters
                  {
                      ValidateIssuerSigningKey = true,
                      IssuerSigningKey = new SymmetricSecurityKey(key),
                      ValidateIssuer = false,
                      ValidateAudience = false
                  };
              });
          }
  }
  </code></pre>
  <p>Chathub:</p>
  <pre><code>[EnableCors(&quot;CorsPolicy&quot;)]
  public class ChatHub : Hub
  {
      private static Dictionary&lt;string, int&gt; onlineClientCounts = new Dictionary&lt;string, int&gt;();
      private static readonly string FrontPrefix = &quot;_FRONT&quot;;
  
      public ChatHub()
      {
      }
  
      [HubMethodName(&quot;ConnectFrontend&quot;)]
      public async Task ConnectFrontend(int sessionId)
      {
          //////
      }
  
      [HubMethodName(&quot;ConnectDevice&quot;)]
      public async Task ConnectDevice(int sessionId)
      {
          //// This method should be called but it isn't.
      }
  
      public void DisConnect(int sessionId, int userId)
      {
         //////////
      }
  
      [HubMethodName(&quot;SendJsonToFrontends&quot;)]
      public async Task SendJsonToFrontends(int sessionId, string jsonString)
      {
          ///
      }
  
      [HubMethodName(&quot;SendJsonToAll&quot;)]
      public async Task SendJsonToAll(int sessionId, string jsonString)
      {
           ////
      }
  }
  </code></pre>
  <p><strong>Angular project</strong></p>
  <p><code>SignalRService</code>:</p>
  <pre><code>export class SignalRService {
  
    private connection: signalR.HubConnection;
  
    public newMessage = new Subject&lt;SocketMessage&gt;();
  
    constructor() {
      
    }
  
    public connectFront() {
  
      this.connection = new signalR.HubConnectionBuilder()
          .withUrl(&quot;http://localhost:2525/chat&quot;)//(environment.baseSignalR)
          .configureLogging(signalR.LogLevel.Trace)
          .build();
  
  
      this.connection.on(&quot;ReceiveJson&quot;, data =&gt; { this.handleJsonMessage(data) });
  
      // handles the first connection message
      this.connection.start().then(() =&gt; this.sendConnectionMessage());
  
      // handles the incoming messages
      this.connection.on(&quot;ReceiveJson&quot;, data =&gt; this.handleJsonMessage(data));
      this.connection.on(&quot;ReceiveJsonFrontend&quot;, data =&gt; this.handleJsonMessage(data));
    }
  
    private sendConnectionMessage() {
      var sessionId = sessionStorage.getItem(&quot;SessionId&quot;);
      if (sessionId != null) {
          this.connection.invoke(&quot;ConnectFrontend&quot;, sessionId).catch((error) =&gt; { debugger; console.log(error); });
      }
    }
  
    public sendWebsocketMessageToAll(msg: SocketMessage) {
      var sessionId = sessionStorage.getItem(&quot;SessionId&quot;);
      if (sessionId != null) {
        this.connection.invoke(&quot;SendJsonToAll&quot;, sessionId, JSON.stringify(msg)).catch((error) =&gt; console.log(error));
      }
    }
  
    public sendWebsocketMessageToFrontend(msg: SocketMessage) {
      var sessionId = sessionStorage.getItem(&quot;SessionId&quot;);
      if (sessionId != null) {
        this.connection.invoke(&quot;SendJsonToFrontends&quot;, sessionId, JSON.stringify(msg)).catch((error) =&gt; console.log(error));
      }
    }
  
    private handleJsonMessage(data: string) {
      this.newMessage.next(this.getSocketMessage(data));
    }
  
    public getSocketMessage(data: string): SocketMessage {
      var msg: SocketMessage = JSON.parse(data);
      return msg;
    }
  
    public disconnect() {
      this.connection.stop();
    }
  }
  
  </code></pre>
  <p>angular output:
  <a href="https://i.stack.imgur.com/X89k1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X89k1.png" alt="enter image description here" /></a></p>
  <p>Api output:
  <a href="https://i.stack.imgur.com/P3rWz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3rWz.png" alt="enter image description here" /></a></p>