【发布时间】:2016-05-10 12:37:50
【问题描述】:
我希望将Node.js 应用程序慢慢转换为ASP.NET WebAPI 2.0。我目前正在使用IIS,并将坚持使用IIS。所以,我想将它们托管在同一台服务器上,但将一些 URI 指向新平台。
我将如何在web.config 中执行此操作? node.js 的当前 web.config 如下所示:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the app.js file is a node.js application
to be handled by the iisnode module -->
<add name="iisnode" path="beta/app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^beta/app.js\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="beta/public{REQUEST_URI}" />
</rule>
<!-- All other URLs are mapped to the Node.js application entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="beta/app.js" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>
文件结构为:
- web.config (the one shown above)
-> node
- app.js
- ...
-> webapi
- web.config
- global.asax
- ...
我在想我应该编写一个新规则,列出要转到WebAPI 的 URI。但是,我不太确定该怎么做。我的猜测是,我会为每个 URI 添加一个带有 input 属性的条件。我也在想我应该指向ASP.NET WebAPI 项目,但我更不知道我应该如何去做,因为Node.js 我只是指向app.js 文件。
【问题讨论】:
-
我认为您的第二条和第三条规则标签中应该有
match标签。并且操作应该类似于<action type="Rewrite" url="beta/app.js?action={R:1}"/>。 {R:1} 是 url 中的匹配部分。由于我不知道您要应用什么规则,您可以提供一些示例。 -
感谢@kiro 的指点。我不确定它是否适用于我正在做的事情,因为原始 node.js
web.config工作正常。您可以在下面的解决方案中看到我需要做的事情。在尝试创建单独的项目时,我做错了一些事情。
标签: iis asp.net-web-api iis-7