没有显示文件端点的页面未找到页面
由于某种原因,Blazor不显示app.razor
在用户在浏览器上键入端点时创建的“找不到”页面,例如文件(示例:localhost:5001/unexist.file )
app.razor
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" >
....
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
...
My custom Not Found page content
...
</LayoutView>
</NotFound>
</Router>
<NavigationTracker />
</CascadingAuthenticationState>
仅当端点不包含任何点字符时,此工作才正确。 有可能控制这一点吗?
For some kind of reasons, Blazor not show the "Not Found" page, created in App.razor
, when users type on their browser a endpoint like a files (example: localhost:5001/unexist.file)
Example when endpoint contains points
App.razor
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" >
....
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
...
My custom Not Found page content
...
</LayoutView>
</NotFound>
</Router>
<NavigationTracker />
</CascadingAuthenticationState>
This work correctly only if endpoint doesn't contains any point characters.
There is a possibility to control this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Looking at Microsoft doc I found this
基本上该方法取决于托管模型:
在您的情况下, Blazor Server (如您的标签所说)。要做到这一点,我们需要更改
。
程序
我在搜索时发现的404个最后一件事,这是我在没有dotnet host的情况下运行Web Assembly独立运行时无法更改路由行为。如果要发布它,它可以根据主机的不同而更改,例如更改web.config,但是在调试模式下我没有运气。
Looking at Microsoft doc I found this helpful information
Basically the method depends on the hosting model:
In your case Blazor server(as your tag says). to do it we need change program.cs as follow:
In blazor web assembly hosted in ASP.Net we change it as follows:
explanation from Microsoft docs:
Last thing I discovered while searching, is that I was unable to change the route behavior when running web assembly standalone without dotnet host. If I were to publish it, it can be change depending on the host, like changing web.config, but I had no luck when in debugging mode.
如果您使用以前的.NET版本,或者使用旧的脚手架,则需要在
program.cs.cs
中更改此配置:If you use a previous version of .Net, or you have an old scaffolding, you need change this configuration in
Program.cs
like this: