当我调用 Hub 方法时,我得到帧响应:
{"invocationId":"1","type":3,"error":"An error occurred while updating the entries. See the inner exception for details."}
如何在不手动调试和使用 step over 的情况下获得详细的错误报告(发生错误的行和文件)并检查代码引发异常的位置。
我在网上找到了很多代码,其中
EnableDetailedErrors
用来services.AddSignalR(options =>
{
options.Hubs.EnableDetailedErrors = true;
});
但是选项(至少在 1.0.0-alpha2-final 版本中)没有属性集线器。
最佳答案
这是您需要在核心中执行的操作(不确定添加的确切版本):
// signalR
services.AddSignalR(options =>
{
if (Environment.IsDevelopment()) {
options.EnableDetailedErrors = true;
}
});
不用说,在生产中默认禁用此功能的原因是出于安全原因。因此,请注意不要暴露您可能不希望“黑客”在您可能抛出的任何异常中看到的内容。
实现上述设置将在浏览器控制台中显示更详细的消息,您也可以在 websocket 调试选项卡中看到:
小建议:
我现在在 ASPNetCore 上设置了两次 SignalR,我想我两次都犯了同样的错误:
// from typescript client arguments are passed like this
this.hubConnection.invoke('SendMessage', 'simon', 'hello');
// not like this
this.hubConnection.invoke('SendMessage', ['simon', 'hello']);
还有
invoke
将等待响应,而 send
才不是。所以你可能看不到使用 send
的错误.
关于signalr - 获取 SignalR Core Hub 方法执行中异常的详细错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46766516/