的情况是这样的:
问题:
我想记住,在cookies上,与视频客户端的网页是最后一次(低质量或高质量)。这样,当客户返回我的网站,按钮将导致他的网页上的视频,他是最后一个。
我使用ASP.NET MVC 2,但我认为这个问题的解决方案可能是一些javascript。
这里的任何帮助都非常感谢!
发布于 2011-05-22 12:01:29
您可以检查这个脚本:http://javascript.internet.com/cookies/cookie-redirect.html
它类似于你所需要的东西。在.js中,必须将last语句更改为类似于以下内容的语句:
if (favorite != null) {
switch (favorite) {
case 'videohq': url = 'url_of_HQ_Video'; // change these!
break;
case 'videolq': url = 'url_of_LQ_Video';
break;
}
然后将其添加到按钮/链接中:
onclick="window.location.href = url"
在您的网站上,您将重定向到这些视频。
还记得要添加设置cookie的代码。您可以添加类似于此的操作:
onClick="SetCookie('video', 'videohq' , exp);
发布于 2011-05-20 15:51:57
Cookie通过每个HTTP请求传递给服务器。
假设您的按钮是在服务器上动态生成的,您可以检查传入的cookie,以查看用户是否将有关参数设置为低质量,并相应地更新按钮URL。
ASP文档
发布于 2011-05-20 16:48:54
从使用ASP.Net WebForms的经验来看,访问cookies非常简单,而且我非常肯定,类似地设置了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);
}
https://stackoverflow.com/questions/6074254
复制相似问题