Hi,
Been trying to get to the bottom of a bug, which I thought was the browsers fault, but it turns out is either:
a) a bug in the browser.
b) a bug in jquery cookie handler.
c) a bug in MVC response handler.
Simple way to replicate this...
Controller
View
(Note: Use the path /Home/Index/{id}, since using the root path (/) appears to work as it should.)
Now, when you load up the page for the first time, you'll see the text "a new cookie" (or whatever you put as the id).
If you hit refresh, the server will receive back the modified cookie (i.e. what jquery modified). BUT you should still see the same output result since the server code should reset the cookie.
But instead, it just keeps adding " another bit" on to the end continuously.
Am I missing something really obvious? Or is the cookie getting cached somewhere and ignoring the server update?
Originally I thought the problem was if you put in an {id}, and then manually changed the address to /Home/Index without an {id}, somehow the cookie update by javascript was being dropped.
I also thought that this was working fine in Firefox, and only IE had the problem, but I've since seen the same behaviour in Firefox.
Regards,
Rob.
Been trying to get to the bottom of a bug, which I thought was the browsers fault, but it turns out is either:
a) a bug in the browser.
b) a bug in jquery cookie handler.
c) a bug in MVC response handler.
Simple way to replicate this...
Controller
Code:
public class HomeController : Controller
{
public ViewResult Index(String id)
{
var cookie = Request.Cookies["test"] ?? new HttpCookie("test") { Expires = DateTime.Now.AddDays(1) };
cookie.Value = (!String.IsNullOrEmpty(id)) ? id : "a new cookie";
Response.Cookies.Add(cookie);
return View();
}
}
Code:
<div id="debug"></div>
<script type="text/javascript" src="/Scripts/jquery.cookie.js"></script>
<script type="text/javascript">
var cookieString = $.cookie("test");
$("#debug").html(cookieString);
$.cookie("test", cookieString + " another bit");
</script>
Now, when you load up the page for the first time, you'll see the text "a new cookie" (or whatever you put as the id).
If you hit refresh, the server will receive back the modified cookie (i.e. what jquery modified). BUT you should still see the same output result since the server code should reset the cookie.
But instead, it just keeps adding " another bit" on to the end continuously.
Am I missing something really obvious? Or is the cookie getting cached somewhere and ignoring the server update?
Originally I thought the problem was if you put in an {id}, and then manually changed the address to /Home/Index without an {id}, somehow the cookie update by javascript was being dropped.
I also thought that this was working fine in Firefox, and only IE had the problem, but I've since seen the same behaviour in Firefox.
Regards,
Rob.
Comment