1

对于 Blazor 服务器托管页面 - 是否可以要求身份验证?基于以下文档:

https://docs.microsoft.com/en-au/aspnet/core/security/authorization/policies?view=aspnetcore-3.0

我已将以下内容添加到我的Startup.cs

public void ConfigureServices(IServiceCollection services)
{
  services.AddMvc().SetCompatibilityVersion( CompatibilityVersion.Version_2_2 );

  services.AddAuthorization(options =>
  {
      options.AddPolicy("Private", policy => policy.RequireAuthenticatedUser() );
  });
}

这是我放在fetchdata页面顶部的内容:

@page "/fetchdata"
@using HollyTest.Data
@inject WeatherForecastService ForecastService
@attribute [Authorize(Policy="Private")]

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from a service.</p>

有人能告诉我我是否走在正确的轨道上吗?

4

0 回答 0