xiazanzhang / dotnet5 Goto Github PK
View Code? Open in Web Editor NEW记一次使用Asp.Net Core WebApi 5.0+Dapper+Mysql+Redis+Docker的开发过程
记一次使用Asp.Net Core WebApi 5.0+Dapper+Mysql+Redis+Docker的开发过程
本来想下载后,看看运行代码,却无法正常运行。检查了nlog发现
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware|The response has already started, the error page middleware will not be executed.
原因是在UserModel.cs里的Required符合但不会出现ErrorMessage
[Required(ErrorMessage = "请输入邮箱")]
[Required(ErrorMessage = "请输入密码")]
[Required(ErrorMessage = "请输入邮箱")]
[EmailAddress(ErrorMessage = "请输入正确的邮箱地址")]
[Required(ErrorMessage = "请输入用户名")]
[MaxLength(length: 12, ErrorMessage = "用户名最大长度不能超过12")]
[MinLength(length: 2, ErrorMessage = "用户名最小长度不能小于2")]
[Required(ErrorMessage = "请输入密码")]
[MaxLength(length: 20, ErrorMessage = "密码最大长度不能超过20")]
[MinLength(length: 6, ErrorMessage = "密码最小长度不能小于6")]
最后解决方法如下是增加 if (!context.Response.HasStarted) 在ErrorHandlingMiddleware.cs 里
// 异常错误信息捕获,将错误信息用Json方式返回
```
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg)
{
if (!context.Response.HasStarted)
{
var result = JsonConvert.SerializeObject(new { Msg = msg, Code = statusCode });
context.Response.ContentType = "application/json;charset=utf-8";
return context.Response.WriteAsync(result);
}
else
{
return context.Response.WriteAsync(string.Empty);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.