Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cookies to switch links

Situation looks like that:

  • I need to have button on my site that will link to subpage with video.
  • There are two subpages - one with high quality video and second with low quality video.
  • When somebody click on button first time then it redirect him to subpage high quality video. From this subpage he can switch to second subpage (with low quality video).

The problem:
I want to remember in cookies on which web page with video client was last in (low or high quality). So that when client returns to my website, button will lead him to page with video that he was last in.

I use ASP.NET MVC 2. But I think that solution to this problem is probably some javascript.

Any help here much appreciated!

like image 745
Marta Avatar asked Nov 30 '25 14:11

Marta


2 Answers

Cookies are passed to the server with each HTTP request.

Assuming your button is generated dynamically on the server, you can inspect the incoming cookies to see if the user has the parameter in question set to low quality and update the button URL accordingly.

ASP docs

like image 156
Dancrumb Avatar answered Dec 03 '25 05:12

Dancrumb


From experience with ASP.Net WebForms, its pretty straightforward to access cookies and I am pretty sure things are setup similarly w/ MVC.

String GetBandwidthSetting()
{
    HttpCookie bandwidth = Context.Request.Cookies["bandwidth"];
    return (bandwidth != null) ? bandwidth.Value : null;
}

String SetBandwidthSetting(String value)
{
    HttpCookie bandwidth = new HttpCookie("bandwidth", value);
    bandwidth.Expires = DateTime.Now.AddYears(1);
    Context.Response.Cookies.Add(bandwidth);
}
like image 26
dana Avatar answered Dec 03 '25 03:12

dana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!