Wednesday, April 15, 2020

Make a .NET Core 3.1.4 Controller catch anything!

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
namespace NotIt.Controllers
{
   [ApiController]
   [Route("/{a?}")]
   [Route("/{b?}/{c?}")]
   [Route("/{d?}/{e?}/{f?}")]
   [Route("/{g?}/{h?}/{i?}/{j?}")]
   [Route("/{k?}/{l?}/{m?}/{n?}/{o?}")]
   [Route("/{p?}/{q?}/{r?}/{s?}/{t?}/{u?}")]
   public class FalloverFailsafeController : ControllerBase
   {
      [HttpGet]
      public IEnumerable<string> Get()
      {
         IEnumerable<string> error = new string[] {"not", "it"};
         return error;
      }
   }
}

 
 

I changed the end of Configure in Startup.cs like so:

app.UseEndpoints(endpoints =>
{
   endpoints.MapControllerRoute(name: "fallover", pattern: "*", defaults: new { controller =
      "FalloverFailsafe", action="Get" });
});

No comments:

Post a Comment