相关疑难解决方法(0)

ASP.NET Core 2.0禁用自动挑战

将我的ASP.NET Core项目升级到2.0后,尝试访问受保护的端点不再返回401,而是重定向到(不存在的)端点以尝试让用户进行身份验证.

所需的行为是应用程序只是返回401.以前我会AutomaticChallenge = false在配置身份验证时设置,但根据这篇文章,设置不再相关(实际上它不再存在).

我的身份验证配置如下:

Startup.cs.ConfigureServices():

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                .AddCookie(o =>
                {
                    o.Cookie.Name = options.CookieName;
                    o.Cookie.Domain = options.CookieDomain;
                    o.SlidingExpiration = true;
                    o.ExpireTimeSpan = options.CookieLifetime;
                    o.TicketDataFormat = ticketFormat;
                    o.CookieManager = new CustomChunkingCookieManager();
                });
Run Code Online (Sandbox Code Playgroud)

配置():

app.UseAuthentication();
Run Code Online (Sandbox Code Playgroud)

如何禁用自动质询,以便在用户未经过身份验证时应用程序返回401?

c# authentication asp.net-core-mvc asp.net-core

20
推荐指数
3
解决办法
2万
查看次数