Signalr/Hub not loading in IIS 7 but working corre

2019-01-10 23:20发布

I am working on a Web Application on the Asp .Net 4.0 framework that uses SignalR, having installed it from the Nuget package. When I debug or run the application without debugging locally it works correctly. However, when it is deployed to the production server it is unable to find the signal/hubs file that is being dynamically injected into the httphandlers. Due to it's dynamic nature it has to be created on the fly, so I can't just copy the working file into the project either.

I have tried the following methods of loading the file:

<script src="/signalr/hubs" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>

And in the code behind:

ScriptManager.GetCurrent(Page).Scripts.Add(new ScriptReference("~/signalr/hubs"));

All of these work locally but not on the server. The path that is rendered in the html looks correct, but there is no file there, delivering a 404 error. If it matters, the server has given the application Full Trust and the application is being run as an application under another site in IIS that uses a subdomain.

9条回答
孤傲高冷的网名
2楼-- · 2019-01-10 23:36

Replace:

<script src="/signalr/hubs" type="text/javascript"></script>

with:

<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
查看更多
冷血范
3楼-- · 2019-01-10 23:38

You Js file should be include like this :

<script src="~/Scripts/jquery.signalR-2.1.1.js"></script>
<script src="~/signalr/hubs"></script>
查看更多
我只想做你的唯一
4楼-- · 2019-01-10 23:39

The above is the answer for this one but I want to point out if you already have URL Rewriting for generic rules which I did and I was confused as to my 404 issue that was not solved by this one, I added the following rule to overwrite my greedy matching that was causing the 404 for URL Rewrite.

<rule name="signalR" stopProcessing="true">
    <match url="^signalr.*" />
    <action type="None" />
</rule>
<!-- greedier rules below -->

This is just here in case someone has a similar issue.

查看更多
登录 后发表回答