Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.47 KB

ASP012.md

File metadata and controls

65 lines (50 loc) · 1.47 KB

ASP012

Don't use [controller]

Topic Value
Id ASP012
Severity Warning
Enabled True
Category AspNetCoreAnalyzers.Routing
Code AttributeAnalyzer

Description

Don't use [controller]. Prefer explicit string so that renaming the class is not a breaking change.

Motivation

[Route("api/[controller]")]
public class SampleDataController : Controller
{
    ...
}

Prefer explicit route with kebab-case.

How to fix violations

Use the code fix to change it to:

[Route("api/sample-data")]
public class SampleDataController : Controller
{
    ...
}

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#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]

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing", 
    "ASP012:Don't use [controller]", 
    Justification = "Reason...")]