Cannot load signalr hubs file correctly after IIS rewrite

喜你入骨 提交于 2020-01-17 03:06:04

问题


I'm working on an application using ASP.NET Web API, SignalR and AngularJS. Ui-router is being used and html5 Mode is enabled.

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>

Everything works great in visualstudio localhost and the auto-generated signalr hubs file is loaded successfully.

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.

I've tried to change the pattern to "~/signalr/(.*)", "~/(signalr)" or "~/signalr but none of these work.

Any suggestion? Thank in advance.


回答1:


Use the following, that should do the trick:

<add input="{REQUEST_URI}" pattern="^/(signalr)" negate="true" />


来源:https://stackoverflow.com/questions/37199218/cannot-load-signalr-hubs-file-correctly-after-iis-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!