Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定js时未加载信号器_C#_Asp.net_Signalr_Bundling And Minification - Fatal编程技术网

C# 绑定js时未加载信号器

C# 绑定js时未加载信号器,c#,asp.net,signalr,bundling-and-minification,C#,Asp.net,Signalr,Bundling And Minification,我一直在asp.net应用程序中使用捆绑和缩小的概念。我在global.asax中有以下代码 void Application_Start(object sender, EventArgs e) { System.Web.Optimization.BundleTable.Bundles.Add(new System.Web.Optimization.ScriptBundle("~/bundle/js") .Include("~/

我一直在asp.net应用程序中使用捆绑和缩小的概念。我在
global.asax中有以下代码

void Application_Start(object sender, EventArgs e)
    {
        System.Web.Optimization.BundleTable.Bundles.Add(new System.Web.Optimization.ScriptBundle("~/bundle/js")
                      .Include("~/Scripts/jquery-1.8.2.js", 
                               "~/Scripts/jquery-ui-1.8.24.js",
                               "~/Scripts/jquery.signalR-2.2.0.js"));
        System.Web.Optimization.BundleTable.Bundles.Add(new System.Web.Optimization.ScriptBundle("~/bundle/js1")
                     .Include("~/Content/Scripts/VerbaTrack.js",
                              "~/Content/Scripts/Helper.js"));
        System.Web.Optimization.BundleTable.Bundles.Add(new System.Web.Optimization.StyleBundle("~/bundle/css")
             .Include("~/Content/Css/Demo.css",
                      "~/Content/Css/Styles.css"));
    }
我在
母版页中以以下方式引用这些文件

<head runat="server">
<link rel="shortcut icon" type="image/x-icon" href="Content/Images/VerbaTrack.ico"/>
<title>

</title>    
<asp:placeholder runat="server">  
     <%= System.Web.Optimization.Scripts.Render("~/bundle/js") %>
     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=drawing,places"></script>    
     <%= System.Web.Optimization.Scripts.Render("~/bundle/js1") %>
     <%= System.Web.Optimization.Styles.Render("~/bundle/css") %>   
     <script src="signalr/hubs"></script>               
</asp:placeholder>

正如您所见,我在引用
jquery.signalr-2.2.0.js

但它仍然抛出以下错误

错误:信号器:未加载信号器。请确保在~/signal/hubs之前引用jquery.signal-x.js。


为什么会这样?

如果脚本没有加载正确的顺序(请检查页面源),您可以使用此选项确保顺序与捆绑包中提供的顺序一致:

/// <summary>
/// Respect the order of the scripts added
/// </summary>
public class NonOrderingBundleOrderer : IBundleOrderer
{
    public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)
    {
        return files;
    }
}
然后附加
NonOrderingBundleOrderer
,并将捆绑添加到捆绑集合:

scripts.Orderer = new NonOrderingBundleOrderer();
BundleTable.Bundles.Add(scripts);

其他JS文件是否像jQuery和jQueryUI JS文件一样被加载?但是只有signarjs文件没有加载?您是否通过查看页面源来检查此问题?
scripts.Orderer = new NonOrderingBundleOrderer();
BundleTable.Bundles.Add(scripts);