I am working on small web application and I am using angular 7 and asp.net core web api as a back end. I am trying to make http post request with angular. My service returns str
The problem behind the dotnet core version. If the dotnet core 2.2.101 then it's have the problem. I have changes latest version i.e. 2.2.102 then it's resolving the issue. Similarly If you get the oldest version of dotnet core<2.2.101 then it's resolve the issue.
I figured out where the problem is located. It's on the server side. Did you use ASP.NET Core 2.2 ? After downgrading to 2.1, it's finally working !
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
</Project>
But I can't understand why. The only thing that changed is in one header, the Server header. It changed from Microsoft-IIS/10.0 (2.2) to Kestrel (2.1)
In ASP.NET Core 2.2, we released a new Server which runs inside IIS for Windows scenarios. The issue you are running into looks like: https://github.com/aspnet/AspNetCore/issues/4398.
When sending the XMLHttpRequest, there is a preflight OPTIONS request which returns a status code of 204. This was incorrectly handled by the IIS server, returning an invalid response to the client.
In your ASP.NET Core application, can you please try the workaround for now:
app.Use(async (ctx, next) =>
{
await next();
if (ctx.Response.StatusCode == 204)
{
ctx.Response.ContentLength = 0;
}
});
in the beginning of Configure
method.
This will also be fixed in the next patch release of ASP.NET Core. I will follow up when the patch is released.
Edit: The latest release (2.2.1) should address this problem: https://dotnet.microsoft.com/download/dotnet-core/2.2. Please try and see if the issue is resolved.