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;
});