Skip to content

Commit

Permalink
Deploying to gh-pages from @ d28c5ae 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Feb 23, 2024
1 parent ccfc380 commit 1aa08a2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
16 changes: 6 additions & 10 deletions rules/S6934/csharp-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing">routing</a> middleware in <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/overview">ASP.NET Core MVC</a> uses a set of predefined rules and conventions to determine which controller and action method to invoke for a given HTTP request. This is typically defined with the <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.controllerendpointroutebuilderextensions.mapcontrollerroute"><code>MapControllerRoute</code></a> method during the application configuration.
However, without some extra configuration on the developer&#8217;s part sometimes the routing system is not able to properly resolve a route and map it to a certain action resulting in unexpected behavior or errors.</p>
<p>The <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing">routing</a> middleware in <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/overview">ASP.NET Core MVC</a> uses a set of predefined rules and conventions to determine which controller and action method to invoke for a given HTTP request. The routing configuration is typically defined with the <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.controllerendpointroutebuilderextensions.mapcontrollerroute"><code>MapControllerRoute</code></a> method during the application configuration.
However, without some extra configuration on the developer&#8217;s part, sometimes the routing system cannot correctly resolve a route and map it to a certain action, resulting in unexpected behavior or errors.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In ASP.NET MVC, when a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routing.httpmethodattribute"><code>HttpMethodAttribute</code></a> (such as <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httpgetattribute"><code>HttpGet</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httppostattribute"><code>HttpPost</code></a>, etc) is specified with a given route template at the action level, it&#8217;s important that its controller also has a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routeattribute"><code>RouteAttribute</code></a> defined. If not then the route pattern defined <code>WebApplication.MapControllerRoute</code> is applied resulting in a not expected route and potential confusion. This applies also to when <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas"><code>areas</code></a> are defined.</p>
<p>In ASP.NET MVC, when a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routing.httpmethodattribute"><code>HttpMethodAttribute</code></a> (such as <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httpgetattribute"><code>HttpGet</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httppostattribute"><code>HttpPost</code></a>, etc) is specified with a given route template at the action level, it&#8217;s important that its controller also has a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routeattribute"><code>RouteAttribute</code></a> defined. If not, then the route pattern that has been defined in <code>WebApplication.MapControllerRoute</code> is applied, resulting in an unexpected route and potential confusion. This applies also to when <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas"><code>areas</code></a> are defined.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_how_to_fix_it">How to fix it</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When any of the controller actions is annotated with a <code>HttpMethodAttribute' with a route template, then you should also annotate the controller with the `RouteAttribute</code> as well.</p>
<p>When any of the controller actions is annotated with a <code>HttpMethodAttribute' with a route template, you should also annotate the controller with the `RouteAttribute</code> as well.</p>
</div>
<div class="sect2">
<h3 id="_code_examples">Code examples</h3>
Expand All @@ -42,7 +42,7 @@ <h4 id="_noncompliant_code_example">Noncompliant code example</h4>
<h4 id="_compliant_solution">Compliant solution</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-csharp" data-lang="csharp"> public class PersonController : Controller
<pre class="highlight"><code class="language-csharp" data-lang="csharp"> public class PersonController: Controller
{
[HttpGet]
public ActionResult Index() // Compliant, no route template is given to the attribute
Expand All @@ -52,7 +52,7 @@ <h4 id="_compliant_solution">Compliant solution</h4>
}

[Route("Person")]
public class PersonController : Controller
public class PersonController: Controller
{
[HttpGet("GetPerson")]
public ActionResult Index() // Compliant
Expand All @@ -71,10 +71,6 @@ <h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>

</div>
<div class="sect2">
<h3 id="_documentation_2">Documentation</h3>
<div class="ulist">
<ul>
<li>
Expand Down
2 changes: 1 addition & 1 deletion rules/S6934/csharp-metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"title":"FIXME","type":"CODE_SMELL","status":"ready","remediation":{"func":"Constant/Issue","constantCost":"5min"},"tags":[],"defaultSeverity":"Major","ruleSpecification":"RSPEC-6934","sqKey":"S6934","scope":"All","defaultQualityProfiles":["Sonar way"],"quickfix":"unknown","code":{"impacts":{"MAINTAINABILITY":"HIGH","RELIABILITY":"MEDIUM","SECURITY":"LOW"},"attribute":"CONVENTIONAL"},"allKeys":["S6934"],"prUrl":"https://github.com/SonarSource/rspec/pull/3676","branch":"rule/add-RSPEC-S6934","languagesSupport":[{"name":"csharp","status":"ready"}]}
{"title":"You should specify the RouteAttribute when an HttpMethodAttribute is specified at an action level","type":"CODE_SMELL","status":"ready","remediation":{"func":"Constant/Issue","constantCost":"5min"},"tags":[],"defaultSeverity":"Major","ruleSpecification":"RSPEC-6934","sqKey":"S6934","scope":"All","defaultQualityProfiles":["Sonar way"],"quickfix":"unknown","code":{"impacts":{"MAINTAINABILITY":"HIGH","RELIABILITY":"MEDIUM","SECURITY":"LOW"},"attribute":"CONVENTIONAL"},"allKeys":["S6934"],"prUrl":"https://github.com/SonarSource/rspec/pull/3676","branch":"rule/add-RSPEC-S6934","languagesSupport":[{"name":"csharp","status":"ready"}]}
16 changes: 6 additions & 10 deletions rules/S6934/default-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing">routing</a> middleware in <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/overview">ASP.NET Core MVC</a> uses a set of predefined rules and conventions to determine which controller and action method to invoke for a given HTTP request. This is typically defined with the <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.controllerendpointroutebuilderextensions.mapcontrollerroute"><code>MapControllerRoute</code></a> method during the application configuration.
However, without some extra configuration on the developer&#8217;s part sometimes the routing system is not able to properly resolve a route and map it to a certain action resulting in unexpected behavior or errors.</p>
<p>The <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing">routing</a> middleware in <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/overview">ASP.NET Core MVC</a> uses a set of predefined rules and conventions to determine which controller and action method to invoke for a given HTTP request. The routing configuration is typically defined with the <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.controllerendpointroutebuilderextensions.mapcontrollerroute"><code>MapControllerRoute</code></a> method during the application configuration.
However, without some extra configuration on the developer&#8217;s part, sometimes the routing system cannot correctly resolve a route and map it to a certain action, resulting in unexpected behavior or errors.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In ASP.NET MVC, when a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routing.httpmethodattribute"><code>HttpMethodAttribute</code></a> (such as <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httpgetattribute"><code>HttpGet</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httppostattribute"><code>HttpPost</code></a>, etc) is specified with a given route template at the action level, it&#8217;s important that its controller also has a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routeattribute"><code>RouteAttribute</code></a> defined. If not then the route pattern defined <code>WebApplication.MapControllerRoute</code> is applied resulting in a not expected route and potential confusion. This applies also to when <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas"><code>areas</code></a> are defined.</p>
<p>In ASP.NET MVC, when a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routing.httpmethodattribute"><code>HttpMethodAttribute</code></a> (such as <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httpgetattribute"><code>HttpGet</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.httppostattribute"><code>HttpPost</code></a>, etc) is specified with a given route template at the action level, it&#8217;s important that its controller also has a <a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routeattribute"><code>RouteAttribute</code></a> defined. If not, then the route pattern that has been defined in <code>WebApplication.MapControllerRoute</code> is applied, resulting in an unexpected route and potential confusion. This applies also to when <a href="https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas"><code>areas</code></a> are defined.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_how_to_fix_it">How to fix it</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When any of the controller actions is annotated with a <code>HttpMethodAttribute' with a route template, then you should also annotate the controller with the `RouteAttribute</code> as well.</p>
<p>When any of the controller actions is annotated with a <code>HttpMethodAttribute' with a route template, you should also annotate the controller with the `RouteAttribute</code> as well.</p>
</div>
<div class="sect2">
<h3 id="_code_examples">Code examples</h3>
Expand All @@ -42,7 +42,7 @@ <h4 id="_noncompliant_code_example">Noncompliant code example</h4>
<h4 id="_compliant_solution">Compliant solution</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-csharp" data-lang="csharp"> public class PersonController : Controller
<pre class="highlight"><code class="language-csharp" data-lang="csharp"> public class PersonController: Controller
{
[HttpGet]
public ActionResult Index() // Compliant, no route template is given to the attribute
Expand All @@ -52,7 +52,7 @@ <h4 id="_compliant_solution">Compliant solution</h4>
}

[Route("Person")]
public class PersonController : Controller
public class PersonController: Controller
{
[HttpGet("GetPerson")]
public ActionResult Index() // Compliant
Expand All @@ -71,10 +71,6 @@ <h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>

</div>
<div class="sect2">
<h3 id="_documentation_2">Documentation</h3>
<div class="ulist">
<ul>
<li>
Expand Down
2 changes: 1 addition & 1 deletion rules/S6934/default-metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"title":"FIXME","type":"CODE_SMELL","status":"ready","remediation":{"func":"Constant/Issue","constantCost":"5min"},"tags":[],"defaultSeverity":"Major","ruleSpecification":"RSPEC-6934","sqKey":"S6934","scope":"All","defaultQualityProfiles":["Sonar way"],"quickfix":"unknown","code":{"impacts":{"MAINTAINABILITY":"HIGH","RELIABILITY":"MEDIUM","SECURITY":"LOW"},"attribute":"CONVENTIONAL"},"allKeys":["S6934"],"prUrl":"https://github.com/SonarSource/rspec/pull/3676","branch":"rule/add-RSPEC-S6934","languagesSupport":[{"name":"csharp","status":"ready"}]}
{"title":"You should specify the RouteAttribute when an HttpMethodAttribute is specified at an action level","type":"CODE_SMELL","status":"ready","remediation":{"func":"Constant/Issue","constantCost":"5min"},"tags":[],"defaultSeverity":"Major","ruleSpecification":"RSPEC-6934","sqKey":"S6934","scope":"All","defaultQualityProfiles":["Sonar way"],"quickfix":"unknown","code":{"impacts":{"MAINTAINABILITY":"HIGH","RELIABILITY":"MEDIUM","SECURITY":"LOW"},"attribute":"CONVENTIONAL"},"allKeys":["S6934"],"prUrl":"https://github.com/SonarSource/rspec/pull/3676","branch":"rule/add-RSPEC-S6934","languagesSupport":[{"name":"csharp","status":"ready"}]}
2 changes: 1 addition & 1 deletion rules/rule-index-store.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rules/rule-index.json

Large diffs are not rendered by default.

0 comments on commit 1aa08a2

Please sign in to comment.