简体   繁体   English

Signalr / hub和jquery脚本上的404错误

[英]404 error on signalr/hubs and on jquery scripts

I've just started using SignalR with C#, seems intresting. 我刚刚开始将SignalR与C#一起使用,似乎很有趣。

I've created an ASP.NET Empty Web Application and followed the tutorial mentioned below 我创建了一个ASP.NET Empty Web Application并按照下面提到的教程进行操作

I found Getting Started with SignalR tutorial on MSDN. 我在MSDN上找到了SignalR入门教程。

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 . 当它在ASP.NET Development Server上运行时,它似乎可以在我的本地计算机上运行。

But when i Deploy the project to my IIS7 , it doesnot work. 但是,当我将项目部署到IIS7 ,它不起作用。

When i checked with the fiddler, it has the results of 404 on all the scripts files included into the html page. 当我与小提琴手检查时,它在html页面中包含的所有脚本文件上都显示404结果。

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. 甚至我也从StackOverflow上的帖子中找到了一些建议,而当我更改web.config文件时,该建议似乎也不起作用。

finally i've modified my web.config according to the FAQ's of SignalR . 最后,我根据SignalRFAQ修改了web.config

Here is my web.config file: 这是我的web.config文件:

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

</configuration>

Global.asax file: Global.asax文件:

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 根据Aron的建议,对Global.asax文件进行了以下更改

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

and now, the jQuery scripts seems to be loading and working as well. 现在, jQuery脚本似乎也正在加载和运行。

Here is the updated error message when hosted on IIS, its from the Console tab of the Browser window. 这是托管在IIS上的更新的错误消息,它来自“浏览器”窗口的“ Console选项卡。

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. 您的IIS设置可能有问题。 Please try adding MIME type for .js extension. 请尝试为.js扩展名添加MIME类型。 Refer this link 引用此链接

404 error may occure when IIS could not handle extension less url 当IIS无法处理扩展名较少的URL时,可能会发生404错误

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

The MSDN article demonstrates how to create SignalR applications in version 2.0. MSDN文章演示了如何在2.0版中创建SignalR应用程序。 But you use signalr 1.0 and probably older verstion of visual studio. 但是您使用signalr 1.0以及Visual Studio的较旧版本。 upgrade the visual studio and use nugget package manager to add signalr 2.0 requirements to your project. 升级Visual Studio,并使用块包管理器将Signalr 2.0要求添加到您的项目中。 I think as a first try it is better to use asp.net web application instead of MVC ( as MSDN article ). 我认为,第一次尝试最好使用asp.net Web应用程序而不是MVC(如MSDN文章)。 So you will not have routing problem. 这样您就不会有路由问题。 I could run the sample with no problem. 我可以毫无问题地运行示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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