2

I have written a PowerShell script in Azure serverless that returns some html

when using the script from Firefox or Chrome, the transmitted html document is opened in the browser as expected, but when using Microsoft's browsers Edge or Internet Explorer, the transmitted html document is downloaded as a file which absolutely is not what we want.

I have tried to modify the content disposition without success.

What should I modify in the script to get IE and Edge to properly show the html content?

here is a part of the code that makes the html document.

foreach ($container in $containers | Sort-Object -Property Name -Descending )
{
    $uri = "list?name=$($container.Name)"
    $HTML += "<li><a href=`"$($uri)`">$($container.Name)</a></li>"+ "`r`n"
}

$HTML += "</ul>"+ "`r`n"
$HTML += "  </body></html>"


$status = [HttpStatusCode]::OK
$body = $HTML

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = $status
    Body = $body
    headers = @{'content-type'='text\html'}
})
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
buildcomplete
  • 552
  • 2
  • 15

2 Answers2

3

The problem seemed to be the header

I changed headers from

@{'content-type'='text\html'} 

to

headers = @{'content-type'='text/html'}

and now it displays correctly, thank to @John Hanley for mentioning 'validation' as validator.w3.org was complaining about the header refusing to parse the document

buildcomplete
  • 552
  • 2
  • 15
0

Seems to be a setting in your local browser not a coding issue. You'll need to change the browser settings in order to solve this:

https://stackoverflow.com/a/17968940/1384539

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • It happens on multiple computers with completely fresh windows 10 installations. no settings should be required to change :) – buildcomplete Jan 21 '20 at 18:44