Topic | Value |
---|---|
Id | ASP012 |
Severity | Warning |
Enabled | True |
Category | AspNetCoreAnalyzers.Routing |
Code | AttributeAnalyzer |
Don't use [controller]. Prefer explicit string so that renaming the class is not a breaking change.
[Route("api/[controller]")]
public class SampleDataController : Controller
{
...
}
Prefer explicit route with kebab-case.
Use the code fix to change it to:
[Route("api/sample-data")]
public class SampleDataController : Controller
{
...
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable ASP012 // Don't use [controller]
Code violating the rule here
#pragma warning restore ASP012 // Don't use [controller]
Or put this at the top of the file to disable all instances.
#pragma warning disable ASP012 // Don't use [controller]
[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing",
"ASP012:Don't use [controller]",
Justification = "Reason...")]