Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

asp.net 4.7 route setup -> asp.net core 2.0 route setup

$
0
0

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");
    }
  }





Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>