【发布时间】:2018-06-28 13:11:42
【问题描述】:
我正在使用 Angular 5 应用程序,我正在尝试实现 SignalR。而且我收到了 2 个错误,我认为它们是同一件事。首先是:
加载资源失败:服务器响应状态为 404(未找到)
第二个是:
ERROR 错误:SignalR:加载集线器时出错。确保您的集线器参考正确,例如.
也就是说,我一直在对此进行研究,并看到了一些主要引用旧版本 siganalR 的选项。
我已关注Tutorial 并添加了一个集线器
[HubName("EventContractHub")]
public class EventContractHub : Hub, IClientHub
{
public void SendId(int id)
{
Clients.All.Send(id);
}
}
Startup.cs 类看起来像...
[assembly:OwinStartUp(typeof(blah.Startup))]
namespace blah
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Other configuration here
app.MapSignalR();
}
}
}
我的_Layout.cshtml 有一个看起来像这样的引用:
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.3.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
有谁知道为什么现在会发生这种情况?
404 not found url 是:http://localhost/IntelliM/signalr/hubs
我应该提一下,我也有一个使用 Owin 在同一台服务器上运行的 api。我不知道这是否会改变什么。如果是这样,我也可以发布配置。
请理解我必须删除这里的一些代码,我留下了相关代码:
public void Configuration(IAppBuilder app)
{
if (/*Logic for License*/)
{
app.Map("/identity", ssocf =>
{
});
}
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthenticationPatched(new OpenIdConnectAuthenticationOptions
{
SignInAsAuthenticationType = "Cookies",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = async n =>
{
/*
* Add Clams here
*/
},
SecurityTokenValidated = async n =>
{
/*Create Token Here*/
},
RedirectToIdentityProvider = n =>
{
}
}
});
//Setting WebAPI Auth
var config = new HttpConfiguration();
config.Formatters.Remove(config.Formatters.XmlFormatter);
//config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = authority
});
app.UseWebApi(config);
app.MapSignalR();
}
}
【问题讨论】:
-
不,不是,我试过
~/signalr/hubs,signalr/hubs,/intellim/signalr/hubs -
如果您阅读了同一个链接教程中的 cmets,那么其他人也会遇到同样的问题。检查以确保您调用的是正确的 URL 路径。
-
还要确保您引用了正确版本的 jquery
-
你提到有另一个 API。 SignalR 何时注册与该服务相关的?它们添加到管道中的顺序也很重要。
-
API注册前后我都试过了。我也会添加 Api 注册。