.NET 9 - Static SSR pages in a globally-interactive app

1.简单介绍

.NET 9 Blazor 新增加的一个feature是在Interactive模式的Blazor站点中可以设定某个页面为Static SSR模式。

这边也简单尝试一下这个新的特性

2.具体说明

2.1 创建项目

  1. 创建一个Blazor Web Assembly的项目,

2)编辑App.razor

复制代码
<head>
	...
    <HeadOutlet @rendermode="@PageRenderMode" />
</head>
<body>
    <Routes @rendermode="@PageRenderMode" />
    ...
</body>
@code {
    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;

    private IComponentRenderMode? PageRenderMode
        => HttpContext.AcceptsInteractiveRouting() ? InteractiveWebAssembly : null;
}

3)把Weather.razor页面变成Static SSR,

复制代码
@page "/weather"
@attribute [ExcludeFromInteractiveRouting]

2.2 运行一下

发现Weather.razor页面能正常工作,同时页面是服务器端渲染之后传到浏览器的

这时如果是从Counter页面跳转到Weather页面,发现服务端会重新渲染并下载的Weather页面

如果Weather.razor页面没有设定 @attribute [ExcludeFromInteractiveRouting]

则Weather页面也是InterActiveWebAssemblyRenderMode的,和别的页面一样的render mode。测试了一下,发现这种情况下从Counter页面跳转到Weather页面是没有从服务器端重新下载Weather页面的。

3.总结

本文简单尝试了一下在全局设定为Interactive(可以为InteractiveServer,InteractiveWebAssembly,

InteractiveAuto)情况下,如何将其中一个页面变成Static SSR,同时看看和未变成Static SSR时候有什么不同的。

如果哪里有错误,麻烦告之,谢谢谢谢!

相关推荐
one9962 小时前
WPF应用程序中的异常处理
c#·.net·wpf
almighty273 小时前
C# ObjectListView实现树状文件夹浏览
c#·树状图·objectlistview·c#树状图·文件显示
ccut 第一混9 小时前
c# 调用basler 相机
c#·halcon·basler
TomCode先生9 小时前
c#动态树形表达式详解
开发语言·c#
上位机付工18 小时前
C#与倍福TwinCAT3进行ADS通信
开发语言·c#
土了个豆子的19 小时前
02.继承MonoBehaviour的单例模式基类
开发语言·visualstudio·单例模式·c#·里氏替换原则
疯狂的维修19 小时前
c#中public类比博图
c#·自动化
土了个豆子的1 天前
03.缓存池
开发语言·前端·缓存·visualstudio·c#
许泽宇的技术分享1 天前
重新定义音频编程:SoundFlow如何以模块化设计革新.NET音频开发生态
.net·音视频