hi all
i'm having a bit of trouble trying to setup the routes in a asp.net core project as i'm trying to port an existing .net 4.7 project across
basically i am trying to route every URL to 1 controller, i could do it with the following in the 4.7 project
public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "AllRoutes", routeTemplate: "{*url}", defaults: new { controller = "Base", }); }
but when i try it in the .net core 2.0 project with the following
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //app.UseMvc(); app.UseMvc(routes => { routes.MapRoute( name: "AllRoutes", template: "{*url}", defaults: new { controller = "Base" } ); }); }
and my base controller
public class BaseController : Controller { [HttpGet] public IActionResult Get() { return Ok("get success"); } // POST api/values [HttpPost] public IActionResult Post([FromBody]string value) { return Ok("post success"); } // PUT api/values/5 [HttpPut] public IActionResult Put([FromBody]string value) { return Ok("put success"); } // DELETE api/values/5 [HttpDelete] public IActionResult Delete() { return Ok("delete success"); } }