Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlugifyParameterTransformer would not work well if specifying route attribute with curly braces {controller}/{action} #20988

Closed
FredHan001 opened this issue Dec 18, 2020 · 7 comments · Fixed by #21075
Assignees
Labels
doc-enhancement Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

@FredHan001
Copy link
Contributor

In section about "Token replacement in route templates [controller], [action], [area]", we can find enclosing a token in curly braces would also be supported, like below.

[Route("{controller}/{action}")]
public IActionResult SomeTestPage()
{
    return Ok("success");
}

It would cause that SlugifyParameterTransformer functionality not work. Using [Route("[controller]/[action]")] on action method, which would work well. I'd like to know why this happens. Thanks.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added ⌚ Not Triaged Source - Docs.ms Docs Customer feedback via GitHub Issue labels Dec 18, 2020
@Rick-Anderson
Copy link
Contributor

Hello! Thanks for contacting us. This sounds like a general question about using ASP.NET Core. While we try to look at and respond to all issues, for questions like this we recommend posting to a community support group like Stack Overflow with the asp.net-core tag.

Potential bugs in the ASP.NET Core framework and product feedback can be reported at dotnet/aspnetcore issues (include full repro steps and cross-link to a repro project in GH when appropriate). For Visual Studio, use the Report a Problem gesture or Suggest a Feature gesture within VS, which open internal issues for the VS team. For Visual Studio Code, you can open an issue at microsoft/vscode issues.

@FredHan001
Copy link
Contributor Author

Hi Rick, thanks for your response. Not sure if it is a potential bug. But if ASP.NET Core developers follow this doc and use curly braces with these token(s) like [Route("{controller}/{action}")] to achieve SlugifyParameterTransformer functionality (this section about "Use a parameter transformer to customize token replacement" also included in same doc), which would not work well. So it will confuse us why doc told curly braces is supported but not working well with SlugifyParameterTransformer scenario.

For convenience, attribute routes support token replacement for reserved route parameters by enclosing a token in one of the following:

  • Square brackets: []
  • Curly braces: {}

@Rick-Anderson
Copy link
Contributor

cc @serpent5

@serpent5
Copy link
Contributor

The implementation shows that an IOutboundParameterTransformer processes only [ and ] when used with attribute routing. I don't know if that is intentional, but it's unusual to see route templates use e.g. {controller} instead of [controller].

@noctis0430
Copy link

When learning ASP.NET Core, developers tend to use consistent syntax. New developers (like myself) was introduced to use curly bracket when learning conventional routing. So I suppose it is normal that new developers tends to use curly bracket as well when comes to attribute routing (even though square bracket is also a viable option) for consistency.

Is it possible to make the use of square bracket and/or curly bracket consistent across both conventional and attribute routing?

@serpent5
Copy link
Contributor

@Rick-Anderson How do you want to proceed with this?

I suggest we update the section to only mention using [] and perhaps redirect the product question/request over to the engineering repo.

@Rick-Anderson
Copy link
Contributor

Agreed.

@Rick-Anderson Rick-Anderson self-assigned this Dec 30, 2020
@Rick-Anderson Rick-Anderson added this to To do in December 2020 via automation Dec 30, 2020
December 2020 automation moved this from To do to Done Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants