If Request("a") <> "" Then
MyC = Request("a")
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & "<br>" & Session("bb"))
Request("a")为链接传过来的值,测试中发现,Session("bb")的传正常。
4 个解决方案
#1
先移除
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " - 1<br>" & Session("bb"))
%>
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " - 1<br>" & Session("bb"))
%>
#2
Cookie是保存在客户端的,要回传一次才可以得到
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " <br>" & Session("bb"))
%>
<script>
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
alert(GetCookie("MyTestCookie"))
</script>
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " <br>" & Session("bb"))
%>
<script>
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
alert(GetCookie("MyTestCookie"))
</script>
#3
上面两位大哥的方法我都试过了,还是不行
但用“孟子E章”的方法,Java弹出窗口中显示是正确的,但Html页面上显示还是不对,请问是什么问题??
注:我设置Cookie和显示是一个页面。
但用“孟子E章”的方法,Java弹出窗口中显示是正确的,但Html页面上显示还是不对,请问是什么问题??
注:我设置Cookie和显示是一个页面。
#4
if (!Page.IsPostBack)没
#1
先移除
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " - 1<br>" & Session("bb"))
%>
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Dim MyCookie As New HttpCookie("MyTestCookie", MyC)
Response.Cookies.Remove("MyTestCookie")
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " - 1<br>" & Session("bb"))
%>
#2
Cookie是保存在客户端的,要回传一次才可以得到
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " <br>" & Session("bb"))
%>
<script>
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
alert(GetCookie("MyTestCookie"))
</script>
<%@ Page Language="vb" Debug="true" %>
<%
Dim MyC As String
If Request("a") <> "" Then
MyC = Request("a")
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
ElseIf Request.Cookies("MyTestCookie") Is Nothing Then
MyC = "01"
Response.Cookies.Clear()
Dim MyCookie As New HttpCookie("MyTestCookie")
MyCookie.Value=MyC
Response.Cookies.Add(MyCookie)
Session("bb") = MyC
End If
Response.Write(Request.Cookies("MyTestCookie").Value & " <br>" & Session("bb"))
%>
<script>
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
alert(GetCookie("MyTestCookie"))
</script>
#3
上面两位大哥的方法我都试过了,还是不行
但用“孟子E章”的方法,Java弹出窗口中显示是正确的,但Html页面上显示还是不对,请问是什么问题??
注:我设置Cookie和显示是一个页面。
但用“孟子E章”的方法,Java弹出窗口中显示是正确的,但Html页面上显示还是不对,请问是什么问题??
注:我设置Cookie和显示是一个页面。
#4
if (!Page.IsPostBack)没