3

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!

5
  • 1
    Please explain where you are having problems. What exactly have you tried and what isn't working?
    – Oded
    May 20, 2011 at 15:39
  • You might want to use localStorage instead, this basically is an object whose values you can fetch and set across pages and in my opinion a lot easier to cope with.
    – pimvdb
    May 20, 2011 at 15:41
  • I would like to use localStorage, but unfortunately not all browsers support it.
    – Marta
    May 20, 2011 at 15:59
  • It sounds like there is a new page request in order to switch from low to high bandwidth. Server cookies will probably be easier to use I'm thinking.
    – dana
    May 20, 2011 at 16:40
  • Yes - those low and high quality videos are on different subpages, so there should be new page request.
    – Marta
    May 20, 2011 at 17:10

3 Answers 3

1

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

1
  • How can I inspect the incoming cookies to see if the user has the parameter in question set?
    – Marta
    May 20, 2011 at 16:03
1

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);
}
1

You can check this script: http://javascript.internet.com/cookies/cookie-redirect.html

It is similar to what you need. In .js you have to change last if statement to one looking similar to that:

if (favorite != null) {
    switch (favorite) {
        case 'videohq': url = 'url_of_HQ_Video'; // change these!
            break;
        case 'videolq': url = 'url_of_LQ_Video';
            break;
    }

And then add this to button/link:

onclick="window.location.href = url"

to your site on which you are redirectiong to those videos.

Remember also to add code that set cookies. You can add action similar to this:

onClick="SetCookie('video', 'videohq' , exp);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.