0无法发布到数据库

0无法发布到数据库

本文介绍了asp.net core 2.0无法发布到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在Windows env上开发并在ubuntu 16.04上运行的Web应用程序.

I have a web application that is being developed on a windows env and runs on ubuntu 16.04.

我在Windows环境中将信息发布到我的sqlite数据库文件blog.db(位于项目的/.目录中)没有问题,但是当我在ubuntu服务器上尝试相同的操作时,出现以下错误:

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:

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.

你们认为问题是什么?这可能是由Nginx引起的吗?还是这是由asp.net引起的?

What do you guys think the problem is? Could this be caused by nginx? Or is this caused by asp.net?

这是我的Controller.cs

Here is my 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

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配置.

It was my nginx configuration.

/./etc/nginx中的文件名为:nginx.conf

within /./etc/nginx is a file called: nginx.conf

我的proxy_set_header连接为升级";

I had proxy_set_header Connection "upgrade";

何时应为proxy_set_header Connection $ http_connection;

when it should be proxy_set_header Connection $http_connection;

这解决了我的问题,现在我的数据库可以在ubuntu端工作.

This fixed my problem and my database now works on the ubuntu side of things.

这篇关于asp.net core 2.0无法发布到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:42