简体   繁体   English

asp.net core 2.0 无法发布到数据库

[英]asp.net core 2.0 Unable to Post to database

I have a web application that is being developed on a windows env and runs on ubuntu 16.04.我有一个正在 Windows env 上开发并在 ubuntu 16.04 上运行的 Web 应用程序。

I have no issues Posting info to my sqlite database file blog.db (located in the /. directory of the project ) in my windows environment, however when I try the same action on my ubuntu server, I get the following error:我在 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()

The problem is, I'm not sure what is causing this error to occur.问题是,我不确定是什么导致了这个错误发生。 I don't think it is an issue with my code, but it is possible.我不认为这是我的代码的问题,但这是可能的。

What do you guys think the problem is?大家觉得问题是什么? Could this be caused by nginx?这可能是由nginx引起的吗? Or is this caused by asp.net?或者这是由asp.net引起的?

Here is my Controller.cs这是我的 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");
    }
}

It was my nginx configuration.这是我的nginx配置。

within /./etc/nginx is a file called: nginx.conf /./etc/nginx 中有一个名为:nginx.conf 的文件

I had proxy_set_header Connection "upgrade";我有 proxy_set_header 连接“升级”;

when it should be proxy_set_header Connection $http_connection;什么时候应该是proxy_set_header Connection $http_connection;

This fixed my problem and my database now works on the ubuntu side of things.这解决了我的问题,我的数据库现在可以在 ubuntu 方面工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM