.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时候有什么不同的。

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

相关推荐
yuanpan19 分钟前
23种设计模式之《组合模式(Composite)》在c#中的应用及理解
开发语言·设计模式·c#·组合模式
csdn_aspnet26 分钟前
ASP.NET MVC AJAX 文件上传
ajax·asp.net·mvc
广拓科技1 小时前
微软量子芯片:开启量子计算新时代?
microsoft·量子计算
滴_咕噜咕噜1 小时前
C#基础总结:常用的数据结构
开发语言·数据结构·c#
技术程序猿华锋2 小时前
OpenAI 周活用户破 4 亿,GPT-4.5 或下周发布,微软加紧扩容服务器
microsoft·chatgpt·deepseek
万兴丶5 小时前
Unity 适用于单机游戏的红点系统(前缀树 | 数据结构 | 设计模式 | 算法 | 含源码)
数据结构·unity·设计模式·c#
程序猿多布6 小时前
C#设计模式 学习笔记
设计模式·c#
code_shenbing8 小时前
.NET MVC实现电影票管理
mvc·.net
软件黑马王子12 小时前
Unity游戏制作中的C#基础(5)条件语句和循环语句知识点全解析
游戏·unity·c#
shepherd枸杞泡茶12 小时前
第3章 3.3日志 .NET Core日志 NLog使用教程
c#·asp.net·.net·.netcore