![](/img/trans.png)
[英]Assembly binding error on ASP.NET MVC WebApi application when published to IIS
[英]Why SignalR is not loaded properly when my ASP.NET MVC application is published on IIS using bundle optimization?
似乎在使用带有IIS的开发服务器上的SignalR运行我的应用程序时,我在JS控制台中收到以下错误(尽管在Debug中本地运行该应用程序完全可以):
Uncaught Error: SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js. at hubs:17 at hubs:106
第17行与以下内容有关:
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
第106行只是IIFE的结尾。
以下是BundleConfig类:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
var scriptBundle = new ScriptBundle("~/Scripts/bundle");
// jQuery
scriptBundle.Include("~/Scripts/jquery-3.1.1.min.js");
// Bootstrap
scriptBundle.Include("~/Scripts/bootstrap.min.js");
// Knockout
scriptBundle.Include("~/Scripts/knockout-{version}.js");
// SignalR
scriptBundle.Include("~/Scripts/jquery.signalR-{version}.js");
// Custom site scripts
scriptBundle.Include("~/Scripts/scripts.js");
scriptBundle.Include("~/Scripts/scripts-bootstrap.js");
scriptBundle.Include("~/Scripts/scripts-devextreme.js");
var styleBundle = new StyleBundle("~/Content/bundle");
// Bootstrap
styleBundle.Include("~/Content/bootstrap-telus-theme.min.css");
// Font Awesome
styleBundle.Include("~/Content/font-awesome.min.css");
// Custom site styles
styleBundle.Include("~/Content/Site.css");
styleBundle.Include("~/Content/Site-bootstrap-plus.css");
styleBundle.Include("~/Content/Site-devextreme-plus.css");
bundles.Add(scriptBundle);
bundles.Add(styleBundle);
#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif
}
}
开发服务器上的文档类型如下:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="author" content="">
<title>Login</title>
<link rel="favicon" href="/Content/favicons/favicon.ico" />
<link rel="favicon" sizes="32x32" href="/Content/favicons/favicon-32.png" />
<link rel="favicon" sizes="128x128" href="/Content/favicons/favicon-128.png" />
<link rel="apple-touch-icon" href="/Content/favicons/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/Content/favicons/apple-touch-icon-72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/Content/favicons/apple-touch-icon-114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/Content/favicons/apple-touch-icon-144.png" />
<link href="/Content/bundle?v=KoFrSDNrdsCobjey_0WoDyRHewQDRrB1Ov9eEHg15EI1" rel="stylesheet"/>
<link href="/Content/DevExtremeBundle?v=dvjWkuzRNPhpuO8epzd1bapDA4VbH3NGrM9XfK6lfH41" rel="stylesheet"/>
<script src="/Scripts/bundle?v=bk8qAjn5FOZNS6DjmQ8qRN1l5sZzYFEHYS7tNOnf4vk1"></script>
<script src="/Scripts/DevExtremeBundle?v=EDbcZoJEzBcOEMDXw50S76TV4vRJy8nCjafsccwoAas1"></script>
<script src="/signalr/hubs" type="text/javascript"></script>
</head>
在本地调试中(因此不进行包优化):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="author" content="">
<title>Login</title>
<link rel="favicon" href="/Content/favicons/favicon.ico" />
<link rel="favicon" sizes="32x32" href="/Content/favicons/favicon-32.png" />
<link rel="favicon" sizes="128x128" href="/Content/favicons/favicon-128.png" />
<link rel="apple-touch-icon" href="/Content/favicons/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/Content/favicons/apple-touch-icon-72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/Content/favicons/apple-touch-icon-114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/Content/favicons/apple-touch-icon-144.png" />
<link href="/Content/bootstrap-telus-theme.min.css" rel="stylesheet"/>
<link href="/Content/font-awesome.min.css" rel="stylesheet"/>
<link href="/Content/Site.css" rel="stylesheet"/>
<link href="/Content/Site-bootstrap-plus.css" rel="stylesheet"/>
<link href="/Content/Site-devextreme-plus.css" rel="stylesheet"/>
<link href="/Content/dx.common.css" rel="stylesheet"/>
<link href="/Content/dx.telus.light.css" rel="stylesheet"/>
<script src="/Scripts/jquery-3.1.1.min.js"></script>
<script src="/Scripts/bootstrap.min.js"></script>
<script src="/Scripts/knockout-3.4.2.debug.js"></script>
<script src="/Scripts/jquery.signalR-2.2.2.js"></script>
<script src="/Scripts/scripts.js"></script>
<script src="/Scripts/scripts-bootstrap.js"></script>
<script src="/Scripts/scripts-devextreme.js"></script>
<script src="/Scripts/cldr.js"></script>
<script src="/Scripts/cldr/event.js"></script>
<script src="/Scripts/cldr/supplemental.js"></script>
<script src="/Scripts/cldr/unresolved.js"></script>
<script src="/Scripts/globalize.js"></script>
<script src="/Scripts/globalize/message.js"></script>
<script src="/Scripts/globalize/number.js"></script>
<script src="/Scripts/globalize/currency.js"></script>
<script src="/Scripts/globalize/date.js"></script>
<script src="/Scripts/jszip.js"></script>
<script src="/Scripts/dx.all.debug.js"></script>
<script src="/Scripts/aspnet/dx.aspnet.data.js"></script>
<script src="/Scripts/aspnet/dx.aspnet.mvc.js"></script>
<script src="/signalr/hubs" type="text/javascript"></script>
</head>
开发服务器上发布的内容没有使用DEBUG常量运行,如果没有它,我如何使它工作? Imho BundleTable.EnableOptimizations = true;
线不应该弄乱我的signalR捆绑,但这仍然是我可以看到的唯一的区别。 但是,当在本地使用开发服务器配置运行时,即使启用了优化捆绑包,它也可以工作...
发生此问题是因为捆绑包优化正在跳过最小文件。 而且您捆绑的JS没有jQuery,这是SignalR必需的。
有关更多详细信息,请检查以下答案: 捆绑软件不包括.min文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.