My ASP.NET Core 2.1 based MVC (client) application consumes webapi.
Client application url: http://testdomain.com:8458/
Web Api url: http://testdomain.com:8404/
On web api action method setting up cookie as below,
public async Task<IActionResult> GetOrdersAsync(string parameter)
{
HttpContext.Response.Cookies.Append(
"cookieKey",
"cookieValue",
new Microsoft.AspNetCore.Http.CookieOptions { IsEssential = true }
);
return Ok();
}
On client MVC application which calls the webapi, in the response object I can see the presence of 'set-cookie' header
[Microsoft.AspNetCore.Cors.EnableCors]
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ShowOrdersAsync(string parameter)
{
var response = await serviceClient.GetOrdersFromBackendAsync(parameter);
return Ok(response);
}
But cookie in the response header, not getting stored in the browser cookie store
What Im missing? how to set the cookie received from webapi app in the client app browser?
On Startup.cs included below pipeline code,
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddDefaultPolicy(
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
// Add framework services.
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=LandingPage}/{id?}");
});
}


