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

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

问题描述

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

回到我将 ASP.NET core 2.2 与 razor 页面一起使用的那一天,它可以使用 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 hostd)"使用 Windows 身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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