大佬教程收集整理的这篇文章主要介绍了Blazor 服务器 - 通过保持根文件夹授权使特定页面匿名,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 .NET5 Blazor 服务器应用程序。我的 Startup.cs 中有以下代码,确保在用户未通过身份验证时始终显示 OKTA 登录页面。
services.AddRazorPages(options =>
{
options.Conventions.Authorizefolder("/");
options.Conventions.AllowAnonymoustopage("/anonymous");
//No error here but no effect either
}
);
如果您注意到我想访问页面“/anonymous”,而无需身份验证。但它总是路由到 OKTA。如何跳过此路由并直接访问“/anonymous”?我必须保留行 options.Conventions.Authorizefolder("/");
我的 App.razor 已启用 CascadingAuthenticationState 视图,该视图也需要保留。
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteVIEw RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<h4>Sorry,you're not authorized to reach this page.</h4>
</NotAuthorized>
<Authorizing>
<h4>Authentication in progress...</h4>
</Authorizing>
</AuthorizeRouteVIEw>
</Found>
<NotFound>
<LayoutVIEw Layout="@typeof(MainLayout)">
<p>Sorry,there's nothing at this address.</p>
</LayoutVIEw>
</NotFound>
</Router>
</CascadingAuthenticationState>
我也试过 appIEd @attribute [AllowAnonymous]。任何线索将不胜感激。
每当您需要匿名页面时,我都会通过使用 .CSHTML 文件代替 .razor 文件来解决这个问题。像“options.Conventions.AllowAnonymousToPage”这样的语句不考虑 .razor 页面,但适用于 .CSHTML 文件。我保留这个线程以获得任何解决方案来申请 .razor 文件。然后将决定使用 .CSHTML 文件进行匿名访问。
以上是大佬教程为你收集整理的Blazor 服务器 - 通过保持根文件夹授权使特定页面匿名全部内容,希望文章能够帮你解决Blazor 服务器 - 通过保持根文件夹授权使特定页面匿名所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。