{"action":"reopened","issue":{"url":"https://api.github.com/repos/aspnet/SignalR/issues/3290","repository_url":"https://api.github.com/repos/aspnet/SignalR","labels_url":"https://api.github.com/repos/aspnet/SignalR/issues/3290/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/SignalR/issues/3290/comments","events_url":"https://api.github.com/repos/aspnet/SignalR/issues/3290/events","html_url":"https://github.com/aspnet/SignalR/issues/3290","id":379285294,"node_id":"MDU6SXNzdWUzNzkyODUyOTQ=","number":3290,"title":"CORS issue with latest SignalR with CORS and MVC with default routes","user":{"login":"sebastienricher","id":6098066,"node_id":"MDQ6VXNlcjYwOTgwNjY=","avatar_url":"https://avatars3.githubusercontent.com/u/6098066?v=4","gravatar_id":"","url":"https://api.github.com/users/sebastienricher","html_url":"https://github.com/sebastienricher","followers_url":"https://api.github.com/users/sebastienricher/followers","following_url":"https://api.github.com/users/sebastienricher/following{/other_user}","gists_url":"https://api.github.com/users/sebastienricher/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastienricher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastienricher/subscriptions","organizations_url":"https://api.github.com/users/sebastienricher/orgs","repos_url":"https://api.github.com/users/sebastienricher/repos","events_url":"https://api.github.com/users/sebastienricher/events{/privacy}","received_events_url":"https://api.github.com/users/sebastienricher/received_events","type":"User","site_admin":false},"labels":[{"id":531772650,"node_id":"MDU6TGFiZWw1MzE3NzI2NTA=","url":"https://api.github.com/repos/aspnet/SignalR/labels/status:%20Investigate","name":"status: Investigate","color":"e580c2","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-11-09T19:07:29Z","updated_at":"2018-12-03T21:17:05Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI'm on the latest version of SignalR Core and using this with Asp.Net Core, using CORS and MVC: On HttpSysServer for server and Angular 4 for client.\r\n\r\nI used to have everything running perfectly (system is in production), but I refactored how my routes are defined. I set them up now using UseMvcWithDefaultRoute. As soon as I switched to this, I got an error message enabling my SignalR connection. If I switch back to only UseMvc, the connection occurs correctly.\r\n\r\nBelow I'll include the relevant code and error message.\r\n\r\nI'm wondering what I don't have correctly configured, but also why a preflight is sent to a websocket request? (Unless it's falling back on another protocol?)\r\n\r\nThanks!\r\n\r\n```csharp\r\npublic void ConfigureServices(IServiceCollection services)\r\n{\r\n\r\n            //...\r\n\r\n            #region  Setup CORS\r\n\r\n            var corsBuilder = new CorsPolicyBuilder();\r\n\r\n\r\n            //corsBuilder.AllowAnyOrigin(); // For anyone access.\r\n            corsBuilder.WithOrigins(new[] { \"http://localhost:4200\",\r\n                                            \"http://productionSite.com\" }); // for a specific url. Don't add a forward slash on the end!\r\n            corsBuilder.AllowAnyHeader();\r\n            corsBuilder.AllowCredentials();\r\n            corsBuilder.AllowAnyMethod();\r\n\r\n            services.AddCors(options =>\r\n            {\r\n                options.AddPolicy(\"SiteCorsPolicy\", corsBuilder.Build());\r\n            });\r\n\r\n            #endregion\r\n\r\n            services.AddSignalR(options =>\r\n            {\r\n                options.EnableDetailedErrors = true;\r\n            });\r\n\r\n            services.AddMvc(config =>\r\n            {\r\n\r\n                // Add XML Content Negotiation\r\n                config.RespectBrowserAcceptHeader = true;\r\n                config.InputFormatters.Add(new XmlSerializerInputFormatter());\r\n                config.OutputFormatters.Add(new XmlSerializerOutputFormatter());\r\n\r\n                // Global exception handler\r\n                config.Filters.Add(typeof(Filters.GlobalExceptionFilterAttribute));\r\n\r\n            });\r\n\r\n            // ...\r\n\r\n}\r\n\r\n```\r\n\r\n```csharp\r\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceScopeFactory scopeFactory, IApplicationLifetime applicationLifetime)\r\n        {\r\n\r\n            // ...\r\n\r\n            app.UseCors(\"SiteCorsPolicy\"); // UseCors() has to be called before UseMvcWithDefaultRoute() and before UseSignalR()\r\n\r\n            app.UseSignalR(routes =>\r\n            {\r\n                routes.MapHub<MainHub>(\"/MainHub\");\r\n            }); // UseSignalR() has to be called after UseCors()\r\n\r\n            app.UseMvcWithDefaultRoute(); // UseMvcWithDefaultRoute() has to be called after UseCors()\r\n\r\n            // app.UseMvc(); // UseMvcWithDefaultRoute() has to be called after UseCors()\r\n\r\n            // app.UseMvc(routes => { routes.MapRoute(\"default\", \"{controller=Home}/{action=Index}/{id?}\"); \r\n\r\n            // ...\r\n\r\n});\r\n        }\r\n```\r\n\r\nAnd error message from the client connecting.\r\n\r\n`Access to XMLHttpRequest at 'http://serverUrl/v1/AppName/MainHub/negotiate' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.\r\n\r\n\r\nUtils.js:193 Warning: Error from HTTP request. 0: \r\n\r\nConsoleLogger.log @ Utils.js:193\r\nxhr.onerror @ HttpClient.js:98\r\nwrapFn @ zone.js:1166\r\nZoneDelegate.invokeTask @ zone.js:425\r\nonInvokeTask @ core.es5.js:3881\r\nZoneDelegate.invokeTask @ zone.js:424\r\nZone.runTask @ zone.js:192\r\nZoneTask.invokeTask @ zone.js:499\r\ninvokeTask @ zone.js:1540\r\nglobalZoneAwareCallback @ zone.js:1566\r\nerror (async)\r\ncustomScheduleGlobal @ zone.js:1666\r\nZoneDelegate.scheduleTask @ zone.js:411\r\nonScheduleTask @ zone.js:301\r\nZoneDelegate.scheduleTask @ zone.js:405\r\nZone.scheduleTask @ zone.js:236\r\nZone.scheduleEventTask @ zone.js:262\r\n(anonymous) @ zone.js:1832\r\n(anonymous) @ http.es5.js:1274\r\nObservable._trySubscribe @ Observable.js:172\r\nObservable.subscribe @ Observable.js:160\r\n(anonymous) @ datasvc.ts:28\r\nZoneAwarePromise @ zone.js:890\r\nDataSvc.makeRequest @ datasvc.ts:27\r\nBorrowService.getAll@ borrow.service.ts:73\r\nBorrowGridComponent.initializeData @ borrow-grid.component.ts:236\r\nBorrowGridComponent.ngOnInit @ borrow-grid.component.ts:101\r\ncheckAndUpdateDirectiveInline @ core.es5.js:10843\r\ncheckAndUpdateNodeInline @ core.es5.js:12341\r\ncheckAndUpdateNode @ core.es5.js:12284\r\ndebugCheckAndUpdateNode @ core.es5.js:13141\r\ndebugCheckDirectivesFn @ core.es5.js:13082\r\n(anonymous) @ BorrowPage.html:23\r\ndebugUpdateDirectives @ core.es5.js:13067\r\ncheckAndUpdateView @ core.es5.js:12251\r\ncallViewAction @ core.es5.js:12599\r\nexecComponentViewsAction @ core.es5.js:12531\r\ncheckAndUpdateView @ core.es5.js:12257\r\ncallViewAction @ core.es5.js:12599\r\nexecEmbeddedViewsAction @ core.es5.js:12557\r\ncheckAndUpdateView @ core.es5.js:12252\r\ncallViewAction @ core.es5.js:12599\r\nexecComponentViewsAction @ core.es5.js:12531\r\ncheckAndUpdateView @ core.es5.js:12257\r\ncallWithDebugContext @ core.es5.js:13467\r\ndebugCheckAndUpdateView @ core.es5.js:13007\r\nViewRef_.detectChanges @ core.es5.js:10174\r\n(anonymous) @ core.es5.js:4812\r\nApplicationRef_.tick @ core.es5.js:4812\r\n(anonymous) @ core.es5.js:4684\r\nZoneDelegate.invoke @ zone.js:392\r\nonInvoke @ core.es5.js:3890\r\nZoneDelegate.invoke @ zone.js:391\r\nZone.run @ zone.js:142\r\nNgZone.run @ core.es5.js:3821\r\nnext @ core.es5.js:4684\r\nschedulerFn @ core.es5.js:3635\r\nSafeSubscriber.__tryOrUnsub @ Subscriber.js:239\r\nSafeSubscriber.next @ Subscriber.js:186\r\nSubscriber._next @ Subscriber.js:127\r\nSubscriber.next @ Subscriber.js:91\r\nSubject.next @ Subject.js:56\r\nEventEmitter.emit @ core.es5.js:3621\r\ncheckStable @ core.es5.js:3855\r\nonHasTask @ core.es5.js:3903\r\nZoneDelegate.hasTask @ zone.js:445\r\nZoneDelegate._updateTaskCount @ zone.js:465\r\nZone._updateTaskCount @ zone.js:289\r\nZone.runTask @ zone.js:209\r\ndrainMicroTaskQueue @ zone.js:602\r\nPromise.then (async)\r\nscheduleMicroTask @ zone.js:585\r\nZoneDelegate.scheduleTask @ zone.js:414\r\nZone.scheduleTask @ zone.js:236\r\nZone.scheduleMicroTask @ zone.js:256\r\nscheduleResolveOrReject @ zone.js:871\r\nZoneAwarePromise.then @ zone.js:981\r\nPlatformRef_._bootstrapModuleWithZone @ core.es5.js:4537\r\nPlatformRef_.bootstrapModule @ core.es5.js:4522\r\n(anonymous) @ main.ts:11\r\n./src/main.ts @ main.bundle.js:1135\r\n__webpack_require__ @ inline.bundle.js:55\r\n0 @ main.bundle.js:1143\r\n__webpack_require__ @ inline.bundle.js:55\r\nwebpackJsonpCallback @ inline.bundle.js:26\r\n(anonymous) @ main.bundle.js:1\r\nUtils.js:190 Error: Failed to complete negotiation with the server: Error\r\nConsoleLogger.log @ Utils.js:190\r\n(anonymous) @ HttpConnection.js:230\r\nstep @ HttpConnection.js:33\r\n(anonymous) @ HttpConnection.js:14\r\nrejected @ HttpConnection.js:6\r\nZoneDelegate.invoke @ zone.js:392\r\nonInvoke @ core.es5.js:3890\r\nZoneDelegate.invoke @ zone.js:391\r\nZone.run @ zone.js:142\r\n(anonymous) @ zone.js:873\r\nZoneDelegate.invokeTask @ zone.js:425\r\nonInvokeTask @ core.es5.js:3881\r\nZoneDelegate.invokeTask @ zone.js:424\r\nZone.runTask @ zone.js:192\r\ndrainMicroTaskQueue @ zone.js:602\r\nZoneTask.invokeTask @ zone.js:503\r\ninvokeTask @ zone.js:1540\r\nglobalZoneAwareCallback @ zone.js:1566\r\nerror (async)\r\ncustomScheduleGlobal @ zone.js:1666\r\nZoneDelegate.scheduleTask @ zone.js:411\r\nonScheduleTask @ zone.js:301\r\nZoneDelegate.scheduleTask @ zone.js:405\r\nZone.scheduleTask @ zone.js:236\r\nZone.scheduleEventTask @ zone.js:262\r\n(anonymous) @ zone.js:1832\r\n(anonymous) @ http.es5.js:1274\r\nObservable._trySubscribe @ Observable.js:172\r\nObservable.subscribe @ Observable.js:160\r\n(anonymous) @ datasvc.ts:28\r\nZoneAwarePromise @ zone.js:890\r\nDataSvc.makeRequest @ datasvc.ts:27\r\nBorrowService.getAll@ borrow.service.ts:73\r\nBorrowGridComponent.initializeData @ borrow-grid.component.ts:236\r\nBorrowGridComponent.ngOnInit @ borrow-grid.component.ts:101\r\ncheckAndUpdateDirectiveInline @ core.es5.js:10843\r\ncheckAndUpdateNodeInline @ core.es5.js:12341\r\ncheckAndUpdateNode @ core.es5.js:12284\r\ndebugCheckAndUpdateNode @ core.es5.js:13141\r\ndebugCheckDirectivesFn @ core.es5.js:13082\r\n(anonymous) @ BorrowPage.html:23\r\ndebugUpdateDirectives @ core.es5.js:13067\r\ncheckAndUpdateView @ core.es5.js:12251\r\ncallViewAction @ core.es5.js:12599\r\nexecComponentViewsAction @ core.es5.js:12531\r\ncheckAndUpdateView @ core.es5.js:12257\r\ncallViewAction @ core.es5.js:12599\r\nexecEmbeddedViewsAction @ core.es5.js:12557\r\ncheckAndUpdateView @ core.es5.js:12252\r\ncallViewAction @ core.es5.js:12599\r\nexecComponentViewsAction @ core.es5.js:12531\r\ncheckAndUpdateView @ core.es5.js:12257\r\ncallWithDebugContext @ core.es5.js:13467\r\ndebugCheckAndUpdateView @ core.es5.js:13007\r\nViewRef_.detectChanges @ core.es5.js:10174\r\n(anonymous) @ core.es5.js:4812\r\nApplicationRef_.tick @ core.es5.js:4812\r\n(anonymous) @ core.es5.js:4684\r\nZoneDelegate.invoke @ zone.js:392\r\nonInvoke @ core.es5.js:3890\r\nZoneDelegate.invoke @ zone.js:391\r\nZone.run @ zone.js:142\r\nNgZone.run @ core.es5.js:3821\r\nnext @ core.es5.js:4684\r\nschedulerFn @ core.es5.js:3635\r\nSafeSubscriber.__tryOrUnsub @ Subscriber.js:239\r\nSafeSubscriber.next @ Subscriber.js:186\r\nSubscriber._next @ Subscriber.js:127\r\nSubscriber.next @ Subscriber.js:91\r\nSubject.next @ Subject.js:56\r\nEventEmitter.emit @ core.es5.js:3621\r\ncheckStable @ core.es5.js:3855\r\nonHasTask @ core.es5.js:3903\r\nZoneDelegate.hasTask @ zone.js:445\r\nZoneDelegate._updateTaskCount @ zone.js:465\r\nZone._updateTaskCount @ zone.js:289\r\nZone.runTask @ zone.js:209\r\ndrainMicroTaskQueue @ zone.js:602\r\nPromise.then (async)\r\nscheduleMicroTask @ zone.js:585\r\nZoneDelegate.scheduleTask @ zone.js:414\r\nZone.scheduleTask @ zone.js:236\r\nZone.scheduleMicroTask @ zone.js:256\r\nscheduleResolveOrReject @ zone.js:871\r\nZoneAwarePromise.then @ zone.js:981\r\nPlatformRef_._bootstrapModuleWithZone @ core.es5.js:4537\r\nPlatformRef_.bootstrapModule @ core.es5.js:4522\r\n(anonymous) @ main.ts:11\r\n./src/main.ts @ main.bundle.js:1135\r\n__webpack_require__ @ inline.bundle.js:55\r\n0 @ main.bundle.js:1143\r\n__webpack_require__ @ inline.bundle.js:55\r\nwebpackJsonpCallback @ inline.bundle.js:26\r\n(anonymous) @ main.bundle.js:1\r\nUtils.js:190 Error: Failed to start the connection: Error\r\nConsoleLogger.log @ Utils.js:190\r\n(anonymous) @ HttpConnection.js:191\r\nstep @ HttpConnection.js:33\r\n(anonymous) @ HttpConnection.js:14\r\nrejected @ HttpConnection.js:6\r\nZoneDelegate.invoke @ zone.js:392\r\nonInvoke @ core.es5.js:3890\r\nZoneDelegate.invoke @ zone.js:391\r\nZone.run @ zone.js:142\r\n(anonymous) @ zone.js:873\r\nZoneDelegate.invokeTask @ zone.js:425\r\nonInvokeTask @ core.es5.js:3881\r\nZoneDelegate.invokeTask @ zone.js:424\r\nZone.runTask @ zone.js:192\r\ndrainMicroTaskQueue @ zone.js:602\r\nZoneTask.invokeTask @ zone.js:503\r\ninvokeTask @ zone.js:1540\r\nglobalZoneAwareCallback @ zone.js:1566\r\nerror (async)\r\ncustomScheduleGlobal @ zone.js:1666\r\nZoneDelegate.scheduleTask @ zone.js:411\r\nonScheduleTask @ zone.js:301\r\nZoneDelegate.scheduleTask @ zone.js:405\r\nZone.scheduleTask @ zone.js:236\r\nZone.scheduleEventTask @ zone.js:262\r\n(anonymous) @ zone.js:1832\r\n(anonymous) @ http.es5.js:1274\r\nObservable._trySubscribe @ Observable.js:172\r\nObservable.subscribe @ Observable.js:160\r\n(anonymous) @ datasvc.ts:28\r\nZoneAwarePromise @ zone.js:890\r\nDataSvc.makeRequest @ datasvc.ts:27\r\nBorrowService.getAll@ borrow.service.ts:73\r\nBorrowGridComponent.initializeData @ borrow-grid.component.ts:236\r\nBorrowGridComponent.ngOnInit @ borrow-grid.component.ts:101\r\ncheckAndUpdateDirectiveInline @ core.es5.js:10843\r\ncheckAndUpdateNodeInline @ core.es5.js:12341\r\ncheckAndUpdateNode @ core.es5.js:12284\r\ndebugCheckAndUpdateNode @ core.es5.js:13141\r\ndebugCheckDirectivesFn @ core.es5.js:13082\r\n(anonymous) @ BorrowPage.html:23\r\ndebugUpdateDirectives @ core.es5.js:13067\r\ncheckAndUpdateView @ core.es5.js:12251\r\ncallViewAction @ core.es5.js:12599\r\nexecComponentViewsAction @ core.es5.js:12531\r\ncheckAndUpdateView @ core.es5.js:12257\r\ncallViewAction @ core.es5.js:12599\r\nexecEmbeddedViewsAction @ core.es5.js:12557\r\ncheckAndUpdateView @ core.es5.js:12252\r\ncallViewAction @ core.es5.js:12599\r\nexecComponentViewsAction @ core.es5.js:12531\r\ncheckAndUpdateView @ core.es5.js:12257\r\ncallWithDebugContext @ core.es5.js:13467\r\ndebugCheckAndUpdateView @ core.es5.js:13007\r\nViewRef_.detectChanges @ core.es5.js:10174\r\n(anonymous) @ core.es5.js:4812\r\nApplicationRef_.tick @ core.es5.js:4812\r\n(anonymous) @ core.es5.js:4684\r\nZoneDelegate.invoke @ zone.js:392\r\nonInvoke @ core.es5.js:3890\r\nZoneDelegate.invoke @ zone.js:391\r\nZone.run @ zone.js:142\r\nNgZone.run @ core.es5.js:3821\r\nnext @ core.es5.js:4684\r\nschedulerFn @ core.es5.js:3635\r\nSafeSubscriber.__tryOrUnsub @ Subscriber.js:239\r\nSafeSubscriber.next @ Subscriber.js:186\r\nSubscriber._next @ Subscriber.js:127\r\nSubscriber.next @ Subscriber.js:91\r\nSubject.next @ Subject.js:56\r\nEventEmitter.emit @ core.es5.js:3621\r\ncheckStable @ core.es5.js:3855\r\nonHasTask @ core.es5.js:3903\r\nZoneDelegate.hasTask @ zone.js:445\r\nZoneDelegate._updateTaskCount @ zone.js:465\r\nZone._updateTaskCount @ zone.js:289\r\nZone.runTask @ zone.js:209\r\ndrainMicroTaskQueue @ zone.js:602\r\nPromise.then (async)\r\nscheduleMicroTask @ zone.js:585\r\nZoneDelegate.scheduleTask @ zone.js:414\r\nZone.scheduleTask @ zone.js:236\r\nZone.scheduleMicroTask @ zone.js:256\r\nscheduleResolveOrReject @ zone.js:871\r\nZoneAwarePromise.then @ zone.js:981\r\nPlatformRef_._bootstrapModuleWithZone @ core.es5.js:4537\r\nPlatformRef_.bootstrapModule @ core.es5.js:4522\r\n(anonymous) @ main.ts:11\r\n./src/main.ts @ main.bundle.js:1135\r\n__webpack_require__ @ inline.bundle.js:55\r\n0 @ main.bundle.js:1143\r\n__webpack_require__ @ inline.bundle.js:55\r\nwebpackJsonpCallback @ inline.bundle.js:26\r\n(anonymous) @ main.bundle.js:1\r\nsignalr.service.ts:53 Error while establishing connection\r\nsignalr.service.ts:54 Error\r\n    at new HttpError (Errors.js:25)\r\n    at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (HttpClient.js:99)\r\n    at XMLHttpRequest.wrapFn (zone.js:1166)\r\n    at ZoneDelegate.invokeTask (zone.js:425)\r\n    at Object.onInvokeTask (core.es5.js:3881)\r\n    at ZoneDelegate.invokeTask (zone.js:424)\r\n    at Zone.runTask (zone.js:192)\r\n    at ZoneTask.invokeTask [as invoke] (zone.js:499)\r\n    at invokeTask (zone.js:1540)\r\n    at XMLHttpRequest.globalZoneAwareCallback (zone.js:1566)`\r\n"}}
{"actor":{"display_login":"muratg"}}