【发布时间】:2016-01-06 16:22:20
【问题描述】:
我是 .Net 开发人员,也是 Node.js 应用程序的新手。我试图通过 Node.js 为我的 ASP.NET MVC 应用程序创建一个代理层来进行跨域通信,而无需触及我的 ASP.NET WebAPI 的服务器级配置。
让我们从代码开始快速理解我的问题,
我创建了一个 MVC 应用程序,将我的节点保存在“MyApp/app.js”和 ASP.NET MVC 视图下,该视图将对我的节点文件进行 AJAX 调用。
<h2>This is an Index page</h2>
<script>
$(function () {
$.ajax({
url: "/sample",
success: function () {
alert('Done');
}
});
});
</script>
下面是我的 web.config,
<handlers>
<!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
<add name="iisnode" path="MyApp/app.js" verb="*" modules="iisnode" />
</handlers>
这是我的 app.js,
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);//When I hardcode to Port:80 I'm getting "Error: listen EACCES 0.0.0.0:80"
app.listen(app.get('port'), function () {
console.log('Express up and listening on port' + app.get('port'));
});
app.get('/Sample', function (req, res) {
res.send('Hello World Sample!');
});
当我尝试打开视图时,AJAX 调用失败并出现“404 错误”。我试图在端口:80 中运行我的 Node 应用程序,但它抛出错误“错误:监听 EACCES 0.0.0.0:80”。为什么我不能在同一个端口上运行我的 Node 应用程序和 ASP.NET MVC 视图?
【问题讨论】:
标签: c# asp.net asp.net-mvc node.js asp.net-mvc-4