27

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.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
PCasagrande
  • 5,302
  • 3
  • 27
  • 36
  • I am experiencing the same issue as well. I seems to get it working on IIS7 and not IIS6 though – user989953 Nov 08 '11 at 16:31
  • This isn't working in IIS7 for us, though IIS6 is installed on the server. IIS6 is only handling the mail however, not the site – PCasagrande Sep 20 '12 at 13:33

10 Answers10

31

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

PCasagrande
  • 5,302
  • 3
  • 27
  • 36
  • Thanks for sharing the solution, it saves my several hours. my scene is serer can't send message to clent. – Sean Apr 26 '13 at 04:54
  • @PCasagrande:- I am having similar problem ..i tried all the things suggested above but no luck..Any help will be appreciable.I am using IIS 5.1 and windows XP. – Pranav Aug 12 '13 at 10:19
  • @Pranav did you install using Nuget? That should do most of the heavy lifting for you. Do you get a 404 error when you navigate to the /signalr/hubs url? – PCasagrande Aug 13 '13 at 15:10
  • Yes i installed using Nuget and i get 404 error while navigating to /signalr/hubs. – Pranav Aug 14 '13 at 05:35
  • Yess! after a few hours, i found this and now it works. Could you explain why we needed those props? – alexmage Sep 30 '13 at 00:08
  • I think it was `runAllManagedModulesForAllRequests` that really fixed things. Basically it turns on the modules that can intercept requests and process them in some way. They are what make .aspx pages do things for example. Here it intercepts the request for a file that doesn't exist and runs the code that ends up creating the output. An explanation is located at http://stackoverflow.com/questions/11048863/modules-runallmanagedmodulesforallrequests-true-meaning – PCasagrande Oct 02 '13 at 00:18
  • I used and it worked. – Ankit Feb 08 '14 at 06:28
9

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

Asciiom
  • 9,867
  • 7
  • 38
  • 57
Girish Sakhare
  • 743
  • 7
  • 14
  • I replaced `` with `` I removed the leading slash to make it a relative path instead of a rooted path. – Wyck Jan 26 '16 at 07:11
4

Replace:

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

with:

<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • This did not work. It outputs the same path as the ScriptManager code I tried, which does not resolve. – PCasagrande Nov 08 '11 at 16:50
  • @PCasagrande, I assume your application is hosted in a virtual directory, so the correct path would be `/appname/signalr/hubs`. Normally the `ResolveUrl` method takes into account the virtual directory name. – Darin Dimitrov Nov 08 '11 at 16:56
  • It is being run as an application under a site, so yes the appname is required. ResolveUrl does address that, but so does the tilde in server side code. The path looks correct, but the file is not there. – PCasagrande Nov 08 '11 at 18:21
  • So what is the resulting url in your browser after using ResolveClientUrl? Does it still return a 404 then? Are you writing an MVC application? Can you hit other extensionless urls in your application? – davidfowl Nov 09 '11 at 03:22
  • @dfowler, It is a Web Forms Web Application. The path it is generating is /HostingCenterStatus/signalr/hubs which sends the request to http://subdomain.domain.com/HostingCenterStatus/signalr/hubs and it returns a 404 error. All of the pages are default.aspx that are navigated to by just using the folder name. – PCasagrande Nov 09 '11 at 13:47
  • @PCasagrande, are you running the application in Integrated Mode in IIS? Or is it Classic Mode? – Darin Dimitrov Nov 09 '11 at 13:48
  • I found the problem and am posting the solution. There were some missing web.config settings. I don't know why it works in Visual Studio without them, but it is working now. – PCasagrande Nov 09 '11 at 14:08
  • Thank you!! Saved my bacon. It was driving me nuts why my hub code wasn't running. – Keith Hill Nov 11 '14 at 01:17
3

You Js file should be include like this :

<script src="~/Scripts/jquery.signalR-2.1.1.js"></script>
<script src="~/signalr/hubs"></script>
Armaan
  • 2,472
  • 2
  • 20
  • 22
  • All the tilde does is say it is affecting the root of the website. The URLs generated were the same. It was an issue with the handlers not firing for the requests. The problem was solved below. – PCasagrande May 04 '16 at 18:56
2

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.

pajo
  • 173
  • 2
  • 7
1

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.

Mike A
  • 46
  • 3
1

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

Cracker0dks
  • 2,422
  • 1
  • 24
  • 39
1

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.

King Friday
  • 25,132
  • 12
  • 90
  • 84
1

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>
estromsnes
  • 146
  • 9
0

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.