Class HomeController
- Namespace
- ProjectTemplate.Web.Controllers
- Assembly
- ProjectTemplate.Web.dll
Controller for handling the home page and error routes.
public class HomeController : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable
- Inheritance
-
HomeController
- Implements
- Inherited Members
Constructors
HomeController(ILogger<HomeController>)
Controller for handling the home page and error routes.
public HomeController(ILogger<HomeController> logger)
Parameters
loggerILogger<HomeController>The logger instance for the controller.
Methods
Error(int?)
Displays an error page for a request routed here by the error-handling pipeline. The response status code comes from the pipeline rather than the route value, and a request that did not arrive through the pipeline is answered with 404 instead of the error page.
[AllowAnonymous]
[Route("Home/Error/{statusCode:int?}")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error(int? statusCode = null)
Parameters
statusCodeint?Status code supplied by the status-code re-execute route. Ignored for direct requests.
Returns
- IActionResult
The error view for a pipeline-routed request; otherwise a 404 result.
Remarks
This route is anonymous by necessity, since it serves errors for unauthenticated requests. Trusting its
route value would let any caller choose the response status code — including values outside the valid
range, such as /Home/Error/0 or /Home/Error/999 — and emit a warning-level log entry per
request. The presence of IStatusCodeReExecuteFeature or
IExceptionHandlerPathFeature is what distinguishes a re-executed request from a direct one.