服务器端Blazor(预览版6)-是否可以要求对特定页面进行身份验证?

时间:2019-07-10 06:45:13

标签: c# blazor-server-side asp.net-core-3.0

对于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>

有人可以告诉我我走的路是否正确吗?

0 个答案:

没有答案