G
Guest
Hi everyone,
Can someone tell me what's wrong with the way that i read a cookie as below:
private void Page_Load(object sender, System.EventArgs e)
{
Response.Cookies.Clear();
HttpCookie cookie = GetSessionCookie("MyCookie", "duh");
}
private HttpCookie GetSessionCookie(string cookieKey, string cookieValue)
{
HttpCookie cookie = Response.Cookies[cookieKey];
if (cookie == null)
{
cookie = this.CreateNewSessionCookie(cookieKey, cookieValue);
}
return cookie;
}
private HttpCookie CreateNewSessionCookie(string cookieKey, string
cookieValue)
{
HttpCookie cookie = new HttpCookie(cookieKey, cookieValue);
Request.Cookies.Add(cookie);
return cookie;
}
The problem is in GetSessionCookie(), after the line
HttpCookie cookie = Response.Cookies[cookieKey];
A new cookie with the specified key is added to the Request.Cookies
collection and the cookie object contains key "MyCookie" with empty value. As
a result, it never reaches the CreateNewSessionCookie() function call. What's
going on, please help me please, anyone?
My Web.Config file contains:
<authentication mode="Forms">
<forms name="MySettings" loginUrl="login.aspx" protection="All"
timeout="20" path="/"></forms>
</authentication>
Many thanks in advance.
KD
Can someone tell me what's wrong with the way that i read a cookie as below:
private void Page_Load(object sender, System.EventArgs e)
{
Response.Cookies.Clear();
HttpCookie cookie = GetSessionCookie("MyCookie", "duh");
}
private HttpCookie GetSessionCookie(string cookieKey, string cookieValue)
{
HttpCookie cookie = Response.Cookies[cookieKey];
if (cookie == null)
{
cookie = this.CreateNewSessionCookie(cookieKey, cookieValue);
}
return cookie;
}
private HttpCookie CreateNewSessionCookie(string cookieKey, string
cookieValue)
{
HttpCookie cookie = new HttpCookie(cookieKey, cookieValue);
Request.Cookies.Add(cookie);
return cookie;
}
The problem is in GetSessionCookie(), after the line
HttpCookie cookie = Response.Cookies[cookieKey];
A new cookie with the specified key is added to the Request.Cookies
collection and the cookie object contains key "MyCookie" with empty value. As
a result, it never reaches the CreateNewSessionCookie() function call. What's
going on, please help me please, anyone?
My Web.Config file contains:
<authentication mode="Forms">
<forms name="MySettings" loginUrl="login.aspx" protection="All"
timeout="20" path="/"></forms>
</authentication>
Many thanks in advance.
KD