1 public override void ConfigureServices(ServiceConfigurationContext context)
2 {
3 context.Services.ConfigureApplicationCookie(options =>
4 options.Events.OnRedirectToLogin = httpContext =>
5 {
6 httpContext.Response.ContentType = "application/json;charset=utf-8";
7 httpContext.Response.Headers["Location"] = httpContext.RedirectUri;
8 httpContext.Response.StatusCode = 401;
9
10 //private readonly IJsonSerializer _jsonSerializer;
11 using (var scope = context.Services.BuildServiceProvider())
12 {
13 var result = new RemoteServiceErrorResponse(
14 new RemoteServiceErrorInfo { Code = httpContext.Response.StatusCode.ToString(), Message = "没有权限,你乱点什么?" });
15
16 httpContext.Response.WriteAsync(scope.GetRequiredService<IJsonSerializer>().Serialize(result));
17 }
18 return System.Threading.Tasks.Task.CompletedTask;
19 });
20 }