【问题标题】:Blazor Server Method Call & Execution DetailsBlazor 服务器方法调用和执行详细信息
【发布时间】:2020-04-03 09:36:56
【问题描述】:

我关注this Blazor Server Counter Increment example

具体代码示例如下。

我有三个问题:

1 - 点击按钮后是否通过 SignalR 调用 IncrementCount?

2 - IncrementCount 的执行是否发生在服务器上? (而不是在浏览器中)

3 - 如果是通过 SignalR - 我如何才能看到使用 Chrome 开发人员工具进行的“调用”(请求)?我查看了网络选项卡,但看不到任何活动。看截图:

代码示例:

@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }
}

【问题讨论】:

  • 取决于您是在向导中选择 Blazor 服务器端还是 Blazor webassembly
  • @Flores 谢谢你,但我说的是这个问题的标题和正文中提到的 Blazor 服务器。
  • 那么1和2的答案是:是的。
  • 在你拥有的网络下的chrome开发者工具中,应该有101个切换协议到websocket。您需要重新加载页面。单击该记录,然后在顶部附近选择“消息”。默认选择“标题”。这是一条二进制消息,因此您不会从中获得太多收益,但您至少可以看到流量。

标签: c# .net-core blazor blazor-server-side


【解决方案1】:

使用 Blazor 服务器

1 - 是的,它通过 SignalR 发生
2 - 是的,它在服务器上运行
3 - SignalR 默认使用 websoket,如果您想在浏览器开发工具中查看 Http 请求,configure SignalR transport to use long pooling
或者使用firefox,可以使用Firefox’s New WebSocket Inspecto

使用 Blazor WASM

1 - 不,它在浏览器上执行
2 - 不,它在浏览器上执行
3 - 没有请求,但你可以 debug using Visual Studio breakpoint 从 3.1-preview4 开始

【讨论】:

  • 对于第 3 点 - 我尝试添加以下内容。但它不起作用,在 chrome 开发工具中看不到任何东西:`endpoints.MapBlazorHub(options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling; });` 还有其他想法怎么看这个?还是我做错了什么?
  • 删除HttpTransportType.WebSockets
  • @fourbeatcoder 带有 WebSocket 检查器的 firefox 新更新
猜你喜欢
  • 2017-07-16
  • 2020-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2018-11-25
  • 2014-08-06
  • 1970-01-01
相关资源
最近更新 更多