Skip to content

Latest commit

 

History

History
66 lines (50 loc) · 1.52 KB

ASP013.md

File metadata and controls

66 lines (50 loc) · 1.52 KB

ASP013

Name the controller to match the route

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

Description

Name the controller to match the route.

Motivation

For keeping the controller name in sync with the route:

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

How to fix violations

Change the name in the above to:

[Route(""api/sample-data"")]
[ApiController]
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 ASP013 // Name the controller to match the route
Code violating the rule here
#pragma warning restore ASP013 // Name the controller to match the route

Or put this at the top of the file to disable all instances.

#pragma warning disable ASP013 // Name the controller to match the route

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing", 
    "ASP013:Name the controller to match the route", 
    Justification = "Reason...")]