心澄欲遣

不践迹,亦不入于室

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 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         }

 

posted on 2021-04-22 15:40  心澄欲遣  阅读(574)  评论(0编辑  收藏  举报
欢迎第myspace graphics个访客