166

以下のコントローラーの例で、内容のないステータス コード 418 を返すようにします。ステータス コードの設定は簡単ですが、リクエストの終了を知らせるために何かを行う必要があるようです。ASP.NET Core より前の MVC または WebForms では呼び出しになる可能性がありますが、存在しないResponse.End()ASP.NET Core ではどのように機能しますか?Response.End

public class ExampleController : Controller
{
    [HttpGet][Route("/example/main")]
    public IActionResult Main()
    {
        this.HttpContext.Response.StatusCode = 418; // I'm a teapot
        // How to end the request?
        // I don't actually want to return a view but perhaps the next
        // line is required anyway?
        return View();   
    }
}
4

5 に答える 5