12

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");
    }
}
jeninja
  • 788
  • 1
  • 13
  • 27
  • I have an asp.net app with debian stretch, nginx, sqlite. Here posts works more less out of the box. One difference I see is the connection string, in my case `"Data Source=tododb.sqlite"`, but don't suspect it to be origin of the problem. – Jonas Bojesen Oct 04 '17 at 06:45
  • I tried changing my connection string to `"Data Source=blog.db"` but still no luck. Maybe the issue is that I am using a `.db` file instead of a `.sqlite`. – jeninja Oct 04 '17 at 17:44
  • I found a similar issue with a potential solution here: https://github.com/aspnet/KestrelHttpServer/issues/1263, will update if the issue is resolved, it most likely has to do with my nginx setup. – jeninja Oct 04 '17 at 17:49
  • 1
    Maybe you can add an answer now and resolve this? – Tjaart Apr 14 '20 at 12:21
  • The answer of @jeninja works for me too. It´s a bug in kestrel. More details here: https://github.com/dotnet/aspnetcore/issues/17081#issuecomment-553741407 – Leonel Urra Alonso May 25 '20 at 06:18

1 Answers1

3

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.

jeninja
  • 788
  • 1
  • 13
  • 27