In ASP.NET core MVC, how do I return a custom HTTP response, along with a custom HTTP code? I wish to be able to build the response myself, and preferably return it from a controller.
public IActionResult Index()
{
// set custom HTTP response and return
}
.... someone fetches Index, and I should be able to manually send a response alike below, where I can control every aspect of the response. I can even work with simply returning a string I build myself.
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
Content-Length: 88
Content-Type: text/html
Connection: Closed
How do I do this in ASP.NET Core MVC?
ControllerBaseorController?Content-LengthandConnection: closed, btw. And the host webserver will usually add its ownServer:header (which you'll have no control over unless you specifically configure your outer web-server or reverse-proxy server). Besides, the whole point of using a framework like ASP.NET Core is to avoid having to mess-around with the low-level details of HTTP.