可以"Blazor(托管ASP.NET Core)"使用Windows身份验证? [英] Can "Blazor (ASP.NET Core hostd)" use windows authentication?

查看:50
本文介绍了可以"Blazor(托管ASP.NET Core)"使用Windows身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Blazor(由ASP.NET Core托管)项目,并托管在IIS上.

当我将ASP.NET Core 2.2与剃须刀页面一起使用时,它可以使用Windows身份验证.

但是对于dotnet core 3.0,只有Blazor服务器端项目模板具有Windows身份验证选项可供选择.

但是Blazor(托管ASP.NET Core)项目模板又如何呢?据我了解,它就像Blazor客户端+ dotnet核心MVC后端.我不明白为什么没有"Windows身份验证"选项.

解决方案

在Blazor WebAssembly应用程序中,用户身份验证和授权必须由后端Web Api处理,因为所有客户端代码都可以由用户修改.

您的ASP.NET Core Api可以使用Windows身份验证,并在cookie中跟踪身份验证状态.在Blazor WebAssembly中,您可以实现 AuthenticationStateProvider ,它调用您的Web Api以获取有关用户身份验证状态的详细信息.

然后,您可以使用 AuthorizeView 组件根据用户的登录状态显示或隐藏内容.

您可以在 Blazor准备授权

https://github.com/Forestbrook/BlazorAuthorizationExample 中的源代码示例.

>

I'm developing a Blazor (ASP.NET Core hosted) project and hosted on IIS.

Back the day when I use ASP.NET core 2.2 with razor page, it can use windows authentication.

However with dotnet core 3.0, only Blazor server-side project template has windows authentication option to choose.

But what about the Blazor (ASP.NET Core hosted) project template? From my understanding, it's just like Blazor client-side + dotnet core MVC backend. I don't understand why there's no "windows authentication" option for it.

解决方案

In Blazor WebAssembly apps, user authentication and authorization must be handled by the back end web Api, because all client-side code can be modified by users.

Your ASP.NET Core Api can use the Windows authentication and keep track of the authentication state in a cookie. In Blazor WebAssembly you can implement an AuthenticationStateProvider which calls your web Api to get details about the authentication state of the user.

Then you can use the AuthorizeView component to show or hide content depending on the users log on state.

A clear description you can find in Blazor Prepare for Authorization

Source code example in https://github.com/Forestbrook/BlazorAuthorizationExample.

这篇关于可以"Blazor(托管ASP.NET Core)"使用Windows身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆