简体   繁体   中英

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.

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.

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

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

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.

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

I had proxy_set_header Connection "upgrade";

when it should be proxy_set_header Connection $http_connection;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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