Websocket连接在.net 4.6中失败

Git*_*111 1 websocket signalr .net-4.6

我有一个适用于4.5的信号器.升级到4.6后,它在Win 2008 R2上运行正常,但在Windows 2012上不起作用.

错误是:

System.InvalidOperationException: WebSockets is unsupported in the current application configuration. To enable this, set the following configuration switch in Web.config:
system.web
httpRuntime targetFramework="4.5" 
system.web
For more information, see http://go.microsoft.com/fwlink/?LinkId=252465.
at  
System.Web.Util.SynchronizationContextUtil.ValidateMode(SynchronizationContextMode currentMode, SynchronizationContextMode requiredMode, String specificErrorMessage)

at System.Web.HttpContext.AcceptWebSocketRequest(Func2 userFunc, AspNetWebSocketOptions options) at Microsoft.AspNet.SignalR.Transports.WebSocketTransport.AcceptWebSocketRequest(Func2 callback)
at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequestPostGroupRead(HostContext context, String groupsToken)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethodT1,T2,T3,TResult
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Mapping.MapMiddleware.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at 

    Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
    at         System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)

如果我将httpRuntime targetFramework ="4.5"添加到web.config,则应用程序根本不会运行.

Git*_*111 5

添加

 <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
Run Code Online (Sandbox Code Playgroud)

到web.config解决了这个问题