简体   繁体   中英

404 error on signalr/hubs and on jquery scripts

I've just started using SignalR with C#, seems intresting.

I've created an ASP.NET Empty Web Application and followed the tutorial mentioned below

I found Getting Started with SignalR tutorial on MSDN.

I've done all the steps mentioned in the tutorial. It seems to work on my local machine when it is being run on ASP.NET Development Server .

But when i Deploy the project to my IIS7 , it doesnot work.

When i checked with the fiddler, it has the results of 404 on all the scripts files included into the html page.

Here is what the fiddler has shown 在此处输入图片说明

Even i've found some suggestions from the posts on StackOverflow, which doesnot seem to work when i change my web.config file as well.

finally i've modified my web.config according to the FAQ's of SignalR .

Here is my web.config file:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
  </system.webServer>

</configuration>

Global.asax file:

public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            // Register the default hubs route: ~/signalr/hubs 
            RouteTable.Routes.MapHubs();
        }
        // Rest of the Methods(Session_Start,Application_BeginRequest..) are empty
     }

I've also changed

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

to

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

and

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

None of them seem to work either.

Do not hesitate to ask if any information required.

Any help would be appreciated


Update

As per the Aron suggestion, the following change is made to the Global.asax file

 RouteTable.Routes.IgnoreRoute("Scripts/");

and now, the jQuery scripts seems to be loading and working as well.

Here is the updated error message when hosted on IIS, its from the Console tab of the Browser window.

SCRIPT5022: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/hubs'></script>.

There may have been problem with your IIS settings. Please try adding MIME type for .js extension. Refer this link

404 error may occure when IIS could not handle extension less url

http://support.microsoft.com/kb/980368

The MSDN article demonstrates how to create SignalR applications in version 2.0. But you use signalr 1.0 and probably older verstion of visual studio. upgrade the visual studio and use nugget package manager to add signalr 2.0 requirements to your project. I think as a first try it is better to use asp.net web application instead of MVC ( as MSDN article ). So you will not have routing problem. I could run the sample with no problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM