Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Routing (Get(int id)) has been broken in latest RC2 #233

Closed
xatabhk opened this issue Nov 20, 2015 · 7 comments
Closed

Routing (Get(int id)) has been broken in latest RC2 #233

xatabhk opened this issue Nov 20, 2015 · 7 comments
Assignees
Milestone

Comments

@xatabhk
Copy link

xatabhk commented Nov 20, 2015

routing_bug_byid
It seems routing has been broken in latest RC2. When the following controller is run on RC2, method 'Get(int id)' receives no hit. If you enter 'http://localhost:9941/api/values/1' or the like in Edge or IE, it reports error 404.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;

namespace tbweb.Controllers
{
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        // GET: api/values
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        [HttpPost("{asfile:bool}")]
        public ActionResult Post(bool asfile, [FromBody]string sRegData)
        {
            return new ObjectResult("xyx");
        }
    }
}

If we remove method 'Post(bool asfile, [FromBody]string sRegData)', 'Get(int id)' will get hits as usual.

I think this is a bug introduced in latest RC2 because I can run the above controller on RC1 final and RC2 weeks ago without any issue.

@anfomin
Copy link

anfomin commented Nov 23, 2015

Routing does not maps to action if first one matched path but did not matched HTTP method or constraint. Simple controller:

public class HomeController : Controller
{
    [HttpGet]
    public IActionResult Index()
    {
        return Content("Index");
    }

    [HttpGet("{id:int}")]
    public IActionResult Item(int id)
    {
        return Content(id.ToString());
    }

    [HttpGet("{name}")]
    public IActionResult Item(string name)
    {
        return Content(name);
    }
}

Everything work OK in rc1-final, bun in Microsoft.AspNet.Routing v1.0.0-rc2-15978 request /asd returns 404.

@anfomin
Copy link

anfomin commented Nov 29, 2015

@rynowak @pranavkm it there any update for this bug? Many routes does not work in RC2...

@rynowak
Copy link
Member

rynowak commented Nov 30, 2015

I'll take a look at this tomorrow and figure out what's going on. We didn't make any major changes is in this area in RC1 so the issue is likely something outside of MVC - you are welcome to say 'told ya so' if I'm wrong 😆

Are you running in IIS? Are you using kestrel/weblistener? Linux/windows/coreclr/desktop/mono?

Does your app have a base-path?

Can you provide your complete startup code?

@xatabhk
Copy link
Author

xatabhk commented Nov 30, 2015

Are you running in IIS? Are you using kestrel/weblistener? Linux/windows/coreclr/desktop/mono?
Does your app have a base-path?
Can you provide your complete startup code?

The test project was created in Visual Studio 2015 via Wizard and then ported to latest RC2.

Steps to reproduce the issue:

  1. Generate a Web API project via Wizard in VS2k15.
  2. Port it to latest RC2.
  3. Add a method like the following one to the controller generated:

[HttpPost("{asfile:bool}")]
public ActionResult Post(bool asfile, [FromBody]string sRegData)
{
return new ObjectResult("xyx");
}

From the log, it seems Attribute Routing was changed in some way recently, so I guess those changes broke asp.net 5 routing.

@rynowak
Copy link
Member

rynowak commented Nov 30, 2015

From the log, it seems Attribute Routing was changed in some way recently, so I guess those changes broke asp.net 5 routing.

Yes, despite my assertions, we actually made a lot of changes in this area in RC2. I'll figure out the issue, thanks 👍

@rynowak
Copy link
Member

rynowak commented Nov 30, 2015

The bug is here: https://github.com/aspnet/Routing/blob/dev/src/Microsoft.AspNet.Routing/AttributeRouting/TreeRouter.cs#L193

This should be a continue not a return.

The effect is that if we ever fail to match a route because of a constraint, we halt instead of continuing and trying other routes. It's likely we have the positive test for this (route with constraints tried before route without), but not the negative.

@rynowak
Copy link
Member

rynowak commented Nov 30, 2015

Fixed by 123eaf2

@rynowak rynowak added this to the 1.0.0-rc2 milestone Nov 30, 2015
@rynowak rynowak self-assigned this Nov 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants