运行node.js&;使用IIS的同一站点的同一服务器上的WebAPI
我希望将运行node.js&;使用IIS的同一站点的同一服务器上的WebAPI,iis,asp.net-web-api,iis-7,Iis,Asp.net Web Api,Iis 7,我希望将Node.js应用程序慢慢转换为ASP.netwebapi 2.0。我目前正在使用IIS,并将坚持使用IIS。因此,我希望将它们托管在同一台服务器上,但将一些URI定向到新平台 如何在web.config中执行此操作?node.js的当前web.config如下所示: <configuration> <system.webServer> <handlers> <!-- indicates that the app.js
Node.js
应用程序慢慢转换为ASP.netwebapi 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>
我想我应该写一条新规则,列出要转到
WebAPI
的URI。但是,我不太确定如何做到这一点。我的猜测是,我将使用input
属性为每个URI
添加一个条件。我还想我应该指向ASP.netwebapi
项目,但我更不知道该如何做,因为Node.js
我只是指向app.js
文件。好的,这就是我最后要做的。事实上,这是非常直截了当的。但当你不熟悉IIS时,它可能会让人望而生畏
我将原始的web.config
放入节点
目录中。我认为如果您不这样做,iisnode
处理程序会干扰WebAPI
config。因此,node
目录中的新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="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^app.js\/debug[\/]?" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>
我认为在你的第二条和第三条规则标签中应该有
match
标签。动作应该类似于
。{R:1}是url中匹配的部分。因为我不知道你想要应用什么规则,你可以提供一些例子。谢谢你的指针@kiro。我不确定它是否适用于我正在做的事情,因为原始的node.jsweb.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="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^app.js\/debug[\/]?" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- test item for webapi folder -->
<rule name="StaticContent2" stopProcessing="true" >
<conditions>
<add input="{REQUEST_URI}" pattern="^/def" />
</conditions>
<action type="Rewrite" url="webapi{REQUEST_URI}" />
</rule>
<!-- rewrite static items which exist on node -->
<rule name="Node Static" stopProcessing="true" >
<conditions>
<add input="{REQUEST_URI}" pattern=".*\.[A-Za-z2]{2,5}$" />
</conditions>
<action type="Rewrite" url="node/public{REQUEST_URI}" />
</rule>
<rule name="WebAPI Version 2" stopProcessing="true">
<conditions>
<add
input="{HEADER_ACCEPT}"
pattern="vnd.fieldops.v2"
ignoreCase="true"
/>
</conditions>
<action type="Rewrite" url="webapi{REQUEST_URI}" />
</rule>
<!-- rewrite to node for dynamic items -->
<rule name="Node Dynamic" stopProcessing="true" >
<conditions>
<add
input="{REQUEST_URI}"
pattern="^/api/(dealerservicereports|chat|dealers|dealerequipment|dealercloseout|publications|tokens|users|\?)"
ignoreCase="true"
/>
</conditions>
<action type="Rewrite" url="node/app.js" />
</rule>
<!-- rewrite everything else to webapi -->
<rule name="WebAPI Dynamic" stopProcessing="true" >
<action type="Rewrite" url="webapi{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>