我正致力于在.Net 4.5.2框架上运行的Web应用程序中的Web表单中调用COM对象。我在使用AspCompat =" true"时收到以下错误消息page指令,它是调用STA(单线程单元)COM对象所必需的:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: <%@ Page AspCompat="true" %> and <httpRuntime apartmentThreading="true" /> are unsupported in the current application configuration. To work around this, add the following configuration switch in Web.config:
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="false" />
</appSettings>
For more information, see http://go.microsoft.com/fwlink/?LinkId=252465.
错误消息指出我需要在web.config文件的应用程序设置中包含 aspnet:UseTaskFriendlySynchronizationContext = false 。这解决了第一个异常,但导致抛出新异常,请求删除应用程序设置,因为应用程序也使用WebSockets(由SignalR使用):
Exception information:
Exception type: InvalidOperationException
Exception message: WebSockets is unsupported in the current application configuration. To work around this, remove the following configuration switch in Web.config:
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" />
</appSettings>
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(Func`2 userFunc, AspNetWebSocketOptions options)
at Microsoft.AspNet.SignalR.Transports.WebSocketTransport.AcceptWebSocketRequest(Func`2 callback)
at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequestPostGroupRead(HostContext context, String groupsToken)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2,T3,TResult](Func`4 func, T1 arg1, T2 arg2, T3 arg3)
是否可以包含AspCompat =&#34; true&#34; Web表单中的页面指令仍然在.Net应用程序的其他地方使用WebSockets(由SignalR使用)?
答案 0 :(得分:0)
是。 SignalR只是一个客户端JavaScript库以及服务器端的处理程序(不是同一个ASP.NET页面)。 另一方面,WebSockets仅在Windows 8或更高版本中受支持,并且必须安装Windows功能。