context.Services.ConfigureApplicationCookie(options => options.Events.OnRedirectToLogin = httpContext => { httpContext.Response.ContentType = "application/json;charset=utf-8"; httpContext.Response.Headers["Location"] = httpContext.RedirectUri; httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized; using (var scope = context.Services.BuildServiceProvider()) { var result = new RemoteServiceErrorResponse( new RemoteServiceErrorInfo { Code = httpContext.Response.StatusCode.ToString(), Message = "Not certified." }); httpContext.Response.WriteAsync(scope.GetRequiredService<IJsonSerializer>().Serialize(result)); } return System.Threading.Tasks.Task.CompletedTask; });
标签:重定向,登录,Services,401,var,httpContext,Response,StatusCode From: https://www.cnblogs.com/xinzheng/p/16611843.html