C# 托管Socket.IO+;在Asp.NETMVC应用程序的虚拟目录中使用IISNode的IIS内部的ExpressJS应用程序
我有一个ASP.NETMVC5应用程序和一个NodeJs(Express+Socket.IO)应用程序。在业务场景中,我必须在MVC应用程序中作为子目录运行NodeJS应用程序 因为。e、 g, MVC: NodeJS: 我使用IISNode(最新版本)在iis8中托管了这两个应用程序。两个应用程序都使用WebSocket。Asp.net应用程序使用信号器,NodeJS使用Socket.IO。我遵循了网站上提供的文档 问题是,当socket.io.js在客户端加载并尝试连接到服务器时,它返回404未找到结果。我已经为应用程序和节点应用程序的server.js附加了web.config。我怀疑问题在于url重写 这里是server.jsC# 托管Socket.IO+;在Asp.NETMVC应用程序的虚拟目录中使用IISNode的IIS内部的ExpressJS应用程序,c#,node.js,socket.io,iis-8,iisnode,C#,Node.js,Socket.io,Iis 8,Iisnode,我有一个ASP.NETMVC5应用程序和一个NodeJs(Express+Socket.IO)应用程序。在业务场景中,我必须在MVC应用程序中作为子目录运行NodeJS应用程序 因为。e、 g, MVC: NodeJS: 我使用IISNode(最新版本)在iis8中托管了这两个应用程序。两个应用程序都使用WebSocket。Asp.net应用程序使用信号器,NodeJS使用Socket.IO。我遵循了网站上提供的文档 问题是,当socket.io.js在客户端加载并尝试连接到服务器时,它返回40
// Load required modules
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module
var easyrtc = require("easyrtc"); // EasyRTC external module
var request = require("request");
var consolidate = require('consolidate');
var https = require('https');
var fs = require('fs');
var options = {key: fs.readFileSync("easyrtc-key.pem"),cert: fs.readFileSync("easyrtc-cert.pem")};
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
var webrtcController = require('./app/controllers/webrtcController');
httpApp.route('/rtc/webrtc/index').get(webrtcController.index);
httpApp.route('/rtc/webrtc/screensender').get(webrtcController.screenSender);
httpApp.route('/rtc/webrtc/screenreceiver').get(webrtcController.screenReceiver);
httpApp.use('/rtc',express.static(__dirname + "/static/"));
httpApp.engine('html',consolidate['swig']);
httpApp.set('view engine', 'html');
httpApp.set('views', './app/views');
// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(process.env.PORT || 1234);
// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":1});
// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);
对于MVC应用程序,web.config是标准的自动生成的配置文件
下面是我的NodeJs应用程序的web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="node/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
NodeJs应用程序中的所有文件都已正确加载,但不知何故我无法连接到websocket。对不起,我忘了提到它是ASP.NET MVC应用程序。@BenjaminTrent谢谢,但我的问题与webrtc无关。它与NodeJS的socket.io有关。对不起,之前它被标记为webrtc…我想我需要学习阅读:)。@RiyaShah你能解决这个问题吗?如果是,请告诉我,我也面临着同样的问题。@ZaidIqbal我在这里回答了这个问题,它有一个完整的IISNode中安装虚拟目录和Socket.io的演练,希望能有所帮助。
self.webSocket = io.connect(serverPath, {
'connect timeout': 10000,
'force new connection': true,
resource: 'node/socket.io'
});