Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置响应状态码,解决未授权时返回的中文信息是unicode格式 #10

Open
ghs79 opened this issue May 23, 2023 · 3 comments

Comments

@ghs79
Copy link

ghs79 commented May 23, 2023

将SimpleAdminResultProvider的方法OnResponseStatusCodes去掉App.GetOptions()?.JsonSerializerOptions
返回值中的中文才不会出现"\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",方能与其它action中的中文一致。

@huguodong
Copy link
Contributor

没看懂

@ghs79
Copy link
Author

ghs79 commented May 23, 2023

当用户没有login时,调用某个方法,会经由SimpleAdminResultProvider的OnResponseStatusCodes返回消息给客户端。这时返回的中文是"\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55"。如果把
// 处理 401 状态码
case StatusCodes.Status401Unauthorized:
await context.Response.WriteAsJsonAsync(RESTfulResult(statusCode, errors: "登录已过期,请重新登录"),
App.GetOptions()?.JsonSerializerOptions);
中的App.GetOptions()?.JsonSerializerOptions去掉,这时在客户端不需要解码,就能接收到正确的汉字“登录已过期,请重新登录”

@huguodong
Copy link
Contributor

好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants