[英]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.