Luci Castle
Luci Castle

Reputation: 35

Azure REST API returns HTML of page

I have deployed my full-stack solution into Azure, containing front-end in Blazor and REST API created in ASP .NET Core. All of the endpoints work except one, which si GET api/shows. When I try to call this via Postman or directly in Azure, then it works fine, but when my front-end tries to call it, then it returns HTML of the index page.

I have managed to get it running yesterday, but now I have published a new version of the front-end and it is not working, again. It looks like Azure does not set request headers, because the one to api/shows has Content-Type: text/html, but in Azure I set headers to be Content-Type: application/json.

In Azure I have set Inbound and Outbound policies to:

<policies>
<inbound>
    <base />
    <set-header name="Accept" exists-action="append">
        <value>application/json</value>
    </set-header>
    <set-header name="Content-Type" exists-action="append">
        <value>application/json</value>
    </set-header>
</inbound>
<backend>
    <base />
</backend>
<outbound>
    <base />
    <set-header name="Content-Type" exists-action="override">
        <value>application/json</value>
    </set-header>
    <set-header name="Accept" exists-action="override">
        <value>application/json</value>
    </set-header>
</outbound>
<on-error>
    <base />
</on-error>
</policies>

These are the response headers of GET api/shows

Accept-Ranges: bytes
Content-Encoding: gzip
Content-Length: 1401
Content-Type: text/html
Date: Sun, 03 Jan 2021 15:41:58 GMT
ETag: "652521af3d0d61:0"
Last-Modified: Sun, 13 Dec 2020 01:55:31 GMT
Server: Microsoft-IIS/10.0
Vary: Accept-Encoding
X-Powered-By: ASP.NET

while other requests, f.e. fetching shows by date GET api/shows/02-01-2021 has

Content-Encoding: gzip
Content-Length: 122
Content-Type: application/json; charset=utf-8
Date: Sun, 03 Jan 2021 15:55:19 GMT
Server: Microsoft-IIS/10.0
Strict-Transport-Security: max-age=2592000
Vary: Accept-Encoding
X-Powered-By: ASP.NET

In the Shows controller:

[HttpGet]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<IEnumerable<MovieShow>>> Get()
{
  var shows = await _mediator.Send(new GetShowsQuery());
  return Ok(shows);
}

EDIT: For fun, I have tried to re-enabling caching in the browser. Suddenly it works fine.

Upvotes: 0

Views: 1216

Answers (1)

Luci Castle
Luci Castle

Reputation: 35

Re-enabling caching in the browser solved the problem. In Chrome, this can be done by opening DevTools (F12). In the Network tab, there is a checkbox for Disable Cache.

Turned it on, refreshed the page and then turned it off worked for me.

Upvotes: 0

Related Questions