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

查看:51
本文介绍了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 中启用 WebSockets 的工具或配置.还是我没有?

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:

更新 SignalR 应用程序的 web.config 文件 以启用为所有请求运行所有托管模块"(简而言之,这是 RAMMFAR 设置).

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

更新使用SignalR与服务器通信的网页:添加对 json2.js 库的引用.添加一个标签,强制内容在最近的浏览器模式下显示.

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.

设置带有 IIS 7.5 的 Windows Server 2008r2 如下:安装 SignalR 应用程序所需的 .NET Framework 版本.创建一个站点并将其与适当的应用程序池相关联.

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:

在页面的head部分添加以下标签.此标记,特别是 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.

按照上述设置步骤后,我能够将 SignalR 入门示例的基于 .NET Framework 4 的版本部署到服务器,并且它在 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天全站免登陆