获取 SignalR Core Hub 方法执行中异常的详细错误
Get detailed error for exception in SignalR Core Hub method execution
当我调用 Hub 方法时,我得到帧响应:
{"invocationId":"1","type":3,"error":"An error occurred while updating
the entries. See the inner exception for details."}
如何在不手动调试和使用单步检查代码引发异常的情况下获取详细的错误报告(发生错误的行和文件)。
在网上我发现了很多使用 EnableDetailedErrors
的代码
services.AddSignalR(options =>
{
options.Hubs.EnableDetailedErrors = true;
});
但选项(至少在版本 1.0.0-alpha2-final 中)没有 属性 集线器。
目前尚未实现启用详细错误的选项。有 an issue 跟踪这个。我的建议是在服务器端打开日志记录 - 原始异常将记录在那里。
这是您需要在核心中执行的操作(不确定添加的确切版本):
// signalR
services.AddSignalR(options =>
{
if (Environment.IsDevelopment()) {
options.EnableDetailedErrors = true;
}
});
不言而喻,在生产中默认禁用此功能的原因是出于安全原因。所以小心不要暴露你可能不希望 'hackers' 在你可能抛出的任何异常中看到的东西。
执行上述设置将在浏览器控制台中显示更详细的消息,您也可以在 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
.
的错误
当我调用 Hub 方法时,我得到帧响应:
{"invocationId":"1","type":3,"error":"An error occurred while updating the entries. See the inner exception for details."}
如何在不手动调试和使用单步检查代码引发异常的情况下获取详细的错误报告(发生错误的行和文件)。
在网上我发现了很多使用 EnableDetailedErrors
的代码
services.AddSignalR(options =>
{
options.Hubs.EnableDetailedErrors = true;
});
但选项(至少在版本 1.0.0-alpha2-final 中)没有 属性 集线器。
目前尚未实现启用详细错误的选项。有 an issue 跟踪这个。我的建议是在服务器端打开日志记录 - 原始异常将记录在那里。
这是您需要在核心中执行的操作(不确定添加的确切版本):
// signalR
services.AddSignalR(options =>
{
if (Environment.IsDevelopment()) {
options.EnableDetailedErrors = true;
}
});
不言而喻,在生产中默认禁用此功能的原因是出于安全原因。所以小心不要暴露你可能不希望 'hackers' 在你可能抛出的任何异常中看到的东西。
执行上述设置将在浏览器控制台中显示更详细的消息,您也可以在 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
.