Skip to content

Conversation

Alex-Sob
Copy link

@Alex-Sob Alex-Sob commented Sep 12, 2025

This PR should address #56791

This PR is adding a new code analysis rule ASP0029: Attribute routing is used for a method that is not an action. The diagnostic should be reported for a controller method if the following conditions are met:

  • The method is not an action, e.g. it's not public or marked with [NonAction] attribute.
  • Attribute routing is used for that method, e.g. it's marked with [Route] or [Http{Method}] or [AcceptVerbs] attributes.

Changes

  • Modified MvcAnalyzer so that it checks non-action methods of a controller to see if a method is marked with an attribute that implements IRouteTemplateProvider. In such a case it reports ASP0029 diagnostic.

  • Added basic unit tests, I could add more if PR is accepted for review.

    I used the same approach for unit tests here that I suggested separately in [Proposal] Performance/usability improvements for analyzer tests #63684

@github-actions github-actions bot added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Sep 12, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant