Coder Social home page Coder Social logo

dotnet5's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dotnet5's Issues

无法正常运行问题,解决方法如下

本来想下载后,看看运行代码,却无法正常运行。检查了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);
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.