0

我正在尝试创建一个 cookie 并计算我访问该页面的次数。这是代码:

<%
var visits=0;
visits=Request.Cookies("count");

if(visits="0") {
    Response.Cookies("count")=1;
    Response.Write("Welcome! You Have Visited This Page First  Time");
}
else {
    Response.Cookies("count")+=1;
    Response.Write("You Have visited this page" + Request.Cookies("count"));
    if(visits="1") {
        Response.Write(" time before");
    }
    else {
        Response.Write(" times before");
    }
}
%>

我得到的输出为:

Welcome! You Have Visited This Page First Time

即使我尝试刷新页面,我也会得到与输出相同的上述语句。提前感谢您的帮助

4

1 回答 1

0

您必须使用==来比较两个值。你正在比较stringand int,但这是错误的。

尝试这个:

if(visits==0) {
于 2013-03-08T12:52:26.397 回答