[英]asp.net core 2.0 Unable to Post to database
我有一个正在 Windows env 上开发并在 ubuntu 16.04 上运行的 Web 应用程序。
我在 Windows 环境blog.db
信息发布到我的 sqlite 数据库文件blog.db
(位于项目的 /. 目录中)没有问题,但是当我在我的 ubuntu 服务器上尝试相同的操作时,我收到以下错误:
Microsoft.AspNetCore.Server.Kestrel[17]
Connection id "0HL8AR4JM7NOJ" bad request data: "Requests with 'Connection: Upgrade' cannot have content in the request body."
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Requests with 'Connection: Upgrade' cannot have content in the request body.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame.ThrowRequestRejected(RequestRejectionReason reason)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.For(HttpVersion httpVersion, FrameRequestHeaders headers, Frame context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()
问题是,我不确定是什么导致了这个错误发生。 我不认为这是我的代码的问题,但这是可能的。
大家觉得问题是什么? 这可能是由nginx引起的吗? 或者这是由asp.net引起的?
这是我的 Controller.cs
private ApplicationDbContext ctx = new ApplicationDbContext();
[HttpPost]
public IActionResult Sent(string name, string info, string email)
{
var message = new ContactMessage
{
username = name,
message = info,
email = email,
date = DateTime.Now
};
ctx.messages.Add(message);
ctx.SaveChanges();
return View();
}
应用程序数据库
public class ApplicationDbContext : DbContext
{
public DbSet<ContactMessage> messages { get; set; }
public DbSet<Post> posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseSqlite("Filename=./blog.db");
}
}
这是我的nginx配置。
/./etc/nginx 中有一个名为:nginx.conf 的文件
我有 proxy_set_header 连接“升级”;
什么时候应该是proxy_set_header Connection $http_connection;
这解决了我的问题,我的数据库现在可以在 ubuntu 方面工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.