How to return a custom HTTP status/message in ASP.NET Core without returning object, IActionResult, etc?
<p>I have an ASP.NET Core Web API site, with Swagger generation and UI enabled. In order for Swagger to work (at least work automatically), the return value from the controller method must be typed. For example,</p>

<pre><code>public async Task&lt;Employee&gt; LoadEmployee(string id)
</code></pre>

<p>However, I need to return custom HTTP status codes and content from this action. All the examples I've seen use the StatusCode method, or return some other object. The problem with this is then Swagger doesn't know what the return type of the action is, and so can't generate the API spec. </p>

<p>Is there some way (Exception, methods on controller, etc) to return the custom code/content, while keeping the signature? I've seen solutions using custom middleware, but it seems like a common enough scenario that there should be something built it. </p>