IIS 7.5上的SignalR WebSockets [英] SignalR WebSockets on IIS 7.5

查看:241
本文介绍了IIS 7.5上的SignalR WebSockets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IIS 7.5上,SignalR应用程序始终使用长轮询. 根据我的搜索,IIS 7.5尚不支持WebSockets.

On my IIS 7.5, my SignalR application always used long polling. As per my search, IIS 7.5 does not support WebSockets yet.

我希望我错过了一些在IIS 7.5中启用WebSocket的工具或配置.还是我没有?

I hope, I missed some tools or configurations to enable WebSockets in IIS 7.5. Or I didn't?

推荐答案

以下是在带有IIS 7.5的Windows 2008r2上托管的必需设置步骤的摘要:

Here's a summary of the required setup steps to host on Windows 2008r2 with IIS 7.5:

Update the SignalR application's web.config file to enable "run all managed modules for all requests" (for short, this is the RAMMFAR setting).

Update the web page that uses SignalR to communicate with the server: Add a reference to the json2.js library. Add a tag that forces the content to display in a recent browser mode.

Set up a Windows Server 2008r2 with IIS 7.5 as follows: Install the .NET Framework version that your SignalR application requires. Create a site and associate it with the appropriate application pool.

更新Signalr应用程序的Web.config文件

在SignalR应用程序的web.config文件中,添加RAMMFAR设置以启用针对所有请求运行所有托管模块.要使SignalR示例应用程序在所有浏览器中的Windows 2008r2和IIS 7.5上运行,都需要此设置.

In your SignalR application's web.config file, add the RAMMFAR setting to enable running all managed modules for all requests. This setting was required to get the SignalR sample application running in on Windows 2008r2 and IIS 7.5 in all browsers.

<system.webServer>
   <modules runAllManagedModulesForAllRequests="true">
   </modules>
</system.webServer> 

更新使用SignalR的网页

在使用SignalR与服务器通信的应用程序网页中,添加以下代码.

In the application web page that uses SignalR to communicate with the server, add the following code.

添加对json2.js JSON解析器库的引用.该脚本为没有它的以前的浏览器版本提供了JSON解析器.您可以通过以下两种方式之一添加脚本: 将NuGet包json2.js添加到您的项目中,然后在您的网页中引用它:

Add a reference to the json2.js JSON parser library. This script provides a JSON parser for previous browser versions that don't have it. You can add the script in one of two ways: Add the NuGet package json2.js to your project, and then reference it in your web page:

或者,也可以在CDN上引用json2.js:

Or as an alternative, reference json2.js on a CDN:

在页面的顶部添加以下标记.此标记(特别是IE = edge值)强制Internet Explorer以可用的最新版本显示内容,而不是妨碍SignalR代码正常工作的早期模式(例如IE7).

Add the following tag in the head section of the page. This tag, specifically the IE=edge value, forces Internet Explorer to display content in the most recent version available, rather than earlier modes (such as IE7) which prevent SignalR code from working.

设置Windows Server 2008r2和IIS 7.5

如前所述,我从.NET 4上的SignalR入门教程构建了示例SignalR应用程序.这是Windows 2008r2和IIS 7.5上的常见托管方案.该服务器是Windows Server 2008r2和IIS 7.5的新的默认默认安装.

As noted, I built the sample SignalR application from the Getting Started with SignalR tutorial on .NET 4. This is a common hosting scenario on Windows 2008r2 and IIS 7.5. The server was a new default default installation of Windows Server 2008r2 and IIS 7.5.

安装所需的.NET Framework版本.在这种情况下,我安装了.NET Framework 4. 在IIS管理器中创建一个新站点,并将该站点与应用程序池关联.使用集成模式应用程序池,SignalR不支持经典模式.对于此应用程序,我使用了ASP.NET v4.0应用程序池.

Install the required .NET Framework version. In this case I installed .NET Framework 4. Create a new site in IIS Manager, and associate the site with an application pool. Use integrated mode application pools, classic mode is not supported for SignalR. For this application I used the ASP.NET v4.0 application pool.

按照上述设置步骤后,我能够将基于.NET Framework 4的SignalR入门示例版本部署到服务器,并且它在IE(版本8、9和10)中运行良好, Chrome和Firefox,即使它使用的是后备传输方式(IE中的永久帧,以及其他浏览器中的服务器发送的事件).对于SignalR开发人员而言,有趣的是,除了上述步骤之外,我无需在应用程序中的任何地方更改一行SignalR代码即可完成这项工作.

After following the above setup steps, I was able to deploy the .NET Framework 4-based version of the Getting Started with SignalR sample to the server, and it worked perfectly in IE (versions 8, 9, and 10), Chrome, and Firefox even though it was using fallback transport methods (forever frames in IE, and server-sent events in the other browsers). The interesting thing for SignalR developers is that apart from the above steps, I didn't have to change a single line of the SignalR code anywhere in the application to make this work.

这是一个简单的情况,但表明SignalR确实确实支持自动回退".服务器上不提供websockets支持时,请使用早期的传输机制.

This is a simple case but shows that SignalR really does support "automatic fallback" to earlier transport mechanisms when websockets support is not available on the server.

这篇关于IIS 7.5上的SignalR WebSockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆