51 lines
923 B
Plaintext
51 lines
923 B
Plaintext
![]() |
=== How to fix it in ASP.NET
|
||
|
|
||
|
include::../../common/fix/code-rationale.adoc[]
|
||
|
|
||
|
[cols="a"]
|
||
|
|===
|
||
|
h| Non-compliant code example
|
||
|
|
|
||
|
[source,csharp]
|
||
|
----
|
||
|
using System.Web;
|
||
|
using System.Web.Mvc;
|
||
|
|
||
|
public class ExampleController : Controller
|
||
|
{
|
||
|
[HttpGet]
|
||
|
public IActionResult CheckCookie(string cookie)
|
||
|
{
|
||
|
if (Request.Cookies["ASP.NET_SessionId"] == null)
|
||
|
{
|
||
|
Response.Cookies.Append("ASP.NET_SessionId", cookie); // Noncompliant
|
||
|
}
|
||
|
|
||
|
return View("Welcome");
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
h| Compliant solution
|
||
|
|
|
||
|
[source,csharp]
|
||
|
----
|
||
|
using System.Web;
|
||
|
using System.Web.Mvc;
|
||
|
|
||
|
public class ExampleController : Controller
|
||
|
{
|
||
|
[HttpGet]
|
||
|
public IActionResult CheckCookie()
|
||
|
{
|
||
|
if (Request.Cookies["ASP.NET_SessionId"] == null)
|
||
|
{
|
||
|
return View("GetCookie");
|
||
|
}
|
||
|
|
||
|
return View("Welcome");
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|===
|
||
|
|
||
|
include::../../common/fix/how-does-this-work.adoc[]
|