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

Attribute Routing: Implement ~/ for overriding a prefix #732

Closed
rynowak opened this issue Jul 1, 2014 · 6 comments
Closed

Attribute Routing: Implement ~/ for overriding a prefix #732

rynowak opened this issue Jul 1, 2014 · 6 comments
Assignees
Milestone

Comments

@rynowak
Copy link
Member

rynowak commented Jul 1, 2014

An attribute route starting with ~/ overrides any value set on the controller with [Route(...)].

Need to modify the code that joins templates + add tests.

@javiercn
Copy link
Member

javiercn commented Jul 7, 2014

RouteAttribute on Controller HttpGet on action Result
[Route("api")] [HttpGet("~/override")] "override"
[Route("~/api")] [HttpGet("~/override")] "override"
[Route("/")] [HttpGet("~/override")] "override"
[Route("")] [HttpGet("~/override")] "override"
null [HttpGet("~/override")] "override" (null meaning no [Route(...)] on the controller
[Route("api")] [HttpGet("/override")] "override"
[Route("~/api")] [HttpGet("/override")] "override"
[Route("/")] [HttpGet("/override")] "override"
[Route("")] [HttpGet("/override")] "override"
null [HttpGet("/override")] "override" (null meaning no [Route(...)] on the controller

I've used HttpGet as a sample, same applies to other verbs. I'm going to start by implementing everything as override and making AttributeRouteTemplate.Combine strip the "" from the left portion of the route, we can discuss if we want to fail early and throw an exception if we see "" on the template for RouteAttribute

Also we need to figure out how "~/" plays with areas. Whether it should override the area or not.

@rynowak Thoughts?

@javiercn
Copy link
Member

javiercn commented Jul 7, 2014

Discussed offline: No need to think of areas for this.

@rynowak
Copy link
Member Author

rynowak commented Jul 7, 2014

Still good question about [Route("~/...")] - my 2c is to be permissive here. Seems silly to throw when we kinda know what you mean already.

Plus there's a reasonable extensibility scenario here. I'm a user, and I implement a global prefix for routes as a convention (using IReflectedApplicationModelConvention). I can use ~/ to escape that prefix (just like we support with action-level routes).

@javiercn
Copy link
Member

javiercn commented Jul 7, 2014

As per discussion offline, we are making "/" and "~/" will expose the same behavior (both will override the value in [Route(...)] The semantics on the table above will be the same for both values

@danroth27 danroth27 modified the milestones: 6.0.0-alpha3, 1.0.0-alpha3 Jul 7, 2014
javiercn added a commit that referenced this issue Jul 8, 2014
This change allows a user to override a route prefix set using
[Route("...")] on the controller by providing a route template
 on the action that starts with "~/" or "/". For example,
 [HttpGet("~/...")] or [HttpGet("/...")]

If the user specifies a template in [Route] that starts with "~/"
or "/", we will just strip the prefix from the template and use
the remaining part of the template.

The reason to do this is that there's a reasonable extensibility
scenario where a user can implement a global prefix for routes as
a convention (using IReflectedApplicationModelConvention), and use
~/ to escape that prefix (just like we support with action-level routes).
@javiercn
Copy link
Member

javiercn commented Jul 8, 2014

@yishaigalatzer @rynowak take a look at the PR

javiercn added a commit that referenced this issue Jul 8, 2014
This change allows a user to override a route prefix set using
[Route("...")] on the controller by providing a route template
 on the action that starts with "~/" or "/". For example,
 [HttpGet("~/...")] or [HttpGet("/...")]

If the user specifies a template in [Route] that starts with "~/"
or "/", we will just strip the prefix from the template and use
the remaining part of the template.

The reason to do this is that there's a reasonable extensibility
scenario where a user can implement a global prefix for routes as
a convention (using IReflectedApplicationModelConvention), and use
~/ to escape that prefix (just like we support with action-level routes).
javiercn added a commit that referenced this issue Jul 10, 2014
This change allows a user to override a route prefix set using
[Route("...")] on the controller by providing a route template
 on the action that starts with "~/" or "/". For example,
 [HttpGet("~/...")] or [HttpGet("/...")]

If the user specifies a template in [Route] that starts with "~/"
or "/", we will just strip the prefix from the template and use
the remaining part of the template.

The reason to do this is that there's a reasonable extensibility
scenario where a user can implement a global prefix for routes as
a convention (using IReflectedApplicationModelConvention), and use
~/ to escape that prefix (just like we support with action-level routes).
javiercn added a commit that referenced this issue Jul 16, 2014
This change allows a user to override a route prefix set using
[Route("...")] on the controller by providing a route template
on the action that starts with "~/" or "/". For example,
[HttpGet("~/...")] or [HttpGet("/...")]

If the user specifies a template in [Route] that starts with "~/"
or "/", we will just strip the prefix from the template and use
the remaining part of the template.

The reason to do this is that there's a reasonable extensibility
scenario where a user can implement a global prefix for routes as
a convention (using IReflectedApplicationModelConvention), and use
~/ to escape that prefix (just like we support with action-level routes).
@javiercn
Copy link
Member

commit 87c430a

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

4 participants