I want to ask that is there any way to read a cookie created by JavaScript code in the Controller?
My application is in ASP.NET Core.
In my View I am creating the cookie by JS like this:
<script type="text/javascript">
document.cookie = "username=John Doe";
</script>
Now in my action method of the controller I try to read the cookie but it did not find any cookie there:
public IActionResult Index()
{
var boh = Request.Cookies["username"];
return View();
}
The value of boh comes out to be null saying no cookie.
I dug a bit deeper and inspected the "Network" area and found that cookie is not added to Response. See the below image:
If I can add the cookie to the response then I think it will be accessible in the controller, but how??
Is there any solution???
Thanks & Regards