Set SignalR connection specific origin does not work in asp,net mvc 4.8

23 Views Asked by At

using asp.net mvc 4.8. I have to set specific origin to signalR connection.

so added above code in Startup.Auth.cs but it does not work.

 CorsPolicy corsPolicy = new CorsPolicy
 {
     AllowAnyHeader = true,
     AllowAnyMethod = true,
     AllowAnyOrigin = false,
     SupportsCredentials = true
 };
 corsPolicy.Origins.Add("https://www.example.com");

 
 _ = app.Map("/signalr", map =>
                 {
                     _ = map.UseCors(new CorsOptions
                     {
                         PolicyProvider = new CorsPolicyProvider
                         {
                             PolicyResolver = context => Task.FromResult(corsPolicy)
                         }
                     });

                     map.RunSignalR();
                 });

I have to set signalr connection only to self domain. by adding above code expected signalr connection should be accepted from https://www.example.com but it allows from all other domains.

0

There are 0 best solutions below