小编Amr*_*raj的帖子

AllowAnonymous 不工作 ASP.Net Core 3.0

我有一个使用 VS 2019 创建的项目,并在项目设置期间启用了 Azure 身份验证。我有一个问题,即在[AllowAnonymous]为应用程序设置控制器时仍然要求用户进行身份验证。

我已经检查了 IIS 并启用了允许匿名,经过一天半的谷歌搜索后,我感到非常茫然。希望有人能帮忙。

为了更好地衡量,这是我的 Startup.cs:

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options));

            //services.AddAuthorization();

            services.AddControllersWithViews(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });
            services.AddRazorPages();

            // Use SQL Database if in Azure, …
Run Code Online (Sandbox Code Playgroud)

.net .net-core asp.net-core asp.net-core-3.0

5
推荐指数
1
解决办法
7109
查看次数

标签 统计

.net ×1

.net-core ×1

asp.net-core ×1

asp.net-core-3.0 ×1