我有一个在Windows env上开发并在ubuntu 16.04上运行的Web应用程序。
我没有问题,在Windows环境中将信息发布到我的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();
}
ApplicationDb.cs
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端工作。