1

I try to make a universal method that will do some stuff. But I get a 404 with any route, even if I hardcode {controller} like api/MyAwesomeController/img/{id}. I know I did something wrong, please help me out.

P.S. I've read this and tried. But here I am

app.UseMvc(routes => {
    routes.MapRoute("media", "api/{controller}/img/{id}",
    defaults: new { controller = "Media", action = "Get" });
});
4
  • 1
    it's better to do attribute routing for web api: learn.microsoft.com/en-us/aspnet/core/tutorials/… Commented Sep 19, 2019 at 3:44
  • it's sure is, but UNIVERSAL is what Im seeking Commented Sep 19, 2019 at 3:51
  • 1
    @Dummy please post your controller Commented Sep 19, 2019 at 3:51
  • @Alexan Allright, I get it, I'll try attrs in an hour, it's dinner time) Will post results after Commented Sep 19, 2019 at 4:38

2 Answers 2

2

Allright. [Route("{tableName}/img/{id}] Attribute to my universal method solved my problem. Thanx 2 @Alexan for pointing me that I already knew the answer and full stomach for good mood.

Sign up to request clarification or add additional context in comments.

Comments

0

You should be mapping in your controller like this

 [Route("api/[controller]")]
 [ApiController]

Your middleware should be use as template for routing and to add some custom route

 app.UseMvc(routes =>
 {
   routes.MapRoute(
      name: "default",
      template: "{controller}/{action=Index}/{id?}");
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.