'While returning file from a endpoint getting message saying: Unrecognized response type; displaying content as text

I am using dotnet core version 6. I have an endpoint in which I am returning .pem file. I am getting responses in strings from the repository and then I am creating a file using stream.

Here is my endpoint:

public async Task<ActionResult> Post([FromBody] User key)
{
        string response = await repository.GetKey(key);
        var stream = new MemoryStream();
        var writer = new StreamWriter(stream);
        writer.Write(response);
        writer.Flush();
        stream.Position = 0;
        return File(stream+".pem", "application/x-pem-file");
}

Is something wrong with my approach? I am getting the file in .txt format instead of .pem format.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source