IIS 重写后无法正确加载信号器集线器文件 [英] Cannot load signalr hubs file correctly after IIS rewrite
问题描述
我正在开发一个使用 ASP.NET Web API、SignalR 和 AngularJS 的应用程序.正在使用 Ui-router 并且 html5 模式已启用.
I'm working on an application using ASP.NET Web API, SignalR and AngularJS. Ui-router is being used and html5 Mode is enabled.
我已经编辑了 web.config 文件,重写规则是这样的:
I've edited the web.config file and the rewrite rule is like this:
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
在visualstudio localhost 中一切正常,并且自动生成的signalr hubs 文件已成功加载.
Everything works great in visualstudio localhost and the auto-generated signalr hubs file is loaded successfully.
问题是当我在服务器(windows server 2008 R2)上部署应用程序并运行应用程序时,<script src="signalr/hubs"></script>
请求信号器集线器文件继续向我发送 index.html 作为响应,我认为原因可能是这行代码<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true"/>
工作不正常,所以请求被重写到根网址.
The problem is when I deployed the application on server (windows server 2008 R2), and run the application, <script src="signalr/hubs"></script>
the request to signalr hubs file keep sending me index.html back as response, which I think the reason may be this line of code
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
is not working correctly so the request is being rewrite to the root url.
我尝试将模式更改为~/signalr/(.*)"、~/(signalr)"或~/signalr,但这些都不起作用.
I've tried to change the pattern to "~/signalr/(.*)", "~/(signalr)" or "~/signalr but none of these work.
有什么建议吗?提前致谢.
Any suggestion? Thank in advance.
推荐答案
使用以下内容,应该可以解决问题:
Use the following, that should do the trick:
<add input="{REQUEST_URI}" pattern="^/(signalr)" negate="true" />
这篇关于IIS 重写后无法正确加载信号器集线器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!