Question

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.

Was it helpful?

Solution

The problem was solved by setting the following flags in the web.config.

<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
        </modules>
    </system.webServer>
</configuration>

For some reason Nuget did not set these values for Elmah or SignalR

OTHER TIPS

I was facing a similar issue, I just changed the /signalr/hubs to /virtualDirectoryName/signalr/hubs and it worked.

Replace:

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

with:

<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>

You Js file should be include like this :

<script src="~/Scripts/jquery.signalR-2.1.1.js"></script>
<script src="~/signalr/hubs"></script>

In our case we had issue with optimizeCompilations attribute in web.config (http://msdn.microsoft.com/en-us/library/ms366723.aspx). Removing optimizeCompilations from web.config solved issue.

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.

I noticed @PCasagrande mentioned in one of the comments that this problem was on a subdomain site.

I had a similar problem and added a rewrite rule to remove the application folder from the url. This solved my 404 error on 'signalr/hubs':

<rule name="Remove SubDomain folder from url" stopProcessing="false">
    <match url="^(.*)SubDomain/(.*)$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="{R:1}{R:2}" />
</rule>

I added the 'remove subdomain' rule before the rewrite rule for the subdomain:

<rule name="Redirect subdomain.domain.com to SubDomain folder" enabled="true">
    <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^subdomain\.domain\.com$" />
    </conditions>
    <action type="Rewrite" url="/SubDomain/{R:0}" />
</rule>

I am also using a subdomain. When using SignalR 0.5.3, I had to modify the web.config:

<system.webServer> 
      <modules> 
        <remove name="UrlRoutingModule-4.0" /> 
        <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> 
      </modules> 
    </system.webServer>

After upgrading to Microsoft.AspNet.SignalR 1.0.0-alpha2 NuGet added an ~/App_Start/RegisterHubs.cs, but I didn't think that was working for me due to using Web Forms and my setup. I had to add RouteTable.Routes.MapHubs(); to my Global.asax Application_Start method.

void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.MapHubs();
    }

Basically make sure you can use the new routing features that were added in .Net 3.5 SP1 (System.Web.Routing). Since SignalR depends on them, you will need to ensure that they are working. Try adding a custom route to test that your routing is working.

My fault was the missing Global.asax file in directory (dll is not enough)

Old post, but still valuable. If someone tried all above options, make sure you put Microsoft.Owin.Host.SystemWeb.dll library into Bin folder of production server. This library is responsible to create /signalr/hubs folder. There is no direct dependency on this library so may be IIS will not through any error without it that's why we forgot to upload it. Hope this will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top