(ASP.NET Web Forms w/ VB.NET)
The Objective:
Inform the user when they have cookies blocked.
What I've done:
From the beginning, I started to write and read cookies and then tried to redirect to a page that notifies the user of the issue. Apparently, (even though I've allowed anonymous access to the destination file), a redirect is not possible so I'm opting for a notification on Login.aspx itself.
I've put all my code in Page_Load(). The first IF statement checks "IF NOT PAGE.ISPOSTBACK" and attempts to write a cookie. The second IF statement then checks the existence of the cookie: "IF REQUEST.COOKIES("MyCookie") IS NOTHING THEN". At this point, I wanted the redirect. Else, do nothing and the user authenticates and is redirected to the main page. I have replaced the redirect with setting the text value of a label on Login.aspx: "LBLAUTHENTICATIonerrorMESSAGE.TXT = <cookies are blocked, yadda, yadda>"
What is happening:
What I've found is that ASP.NET ALREADY keeps the user on Login.aspx and doesn't authenticate the user if they've blocked cookies in their browser. Ok, so I can live with the label being used to notify the user. But the label is always left blank.
When I step through my stop points to check the values, my code logic works and the correct value is place into the label, but it appears to do another post-back - and I lose my value. The same thing happens if I use a session variable.
OUTSIDE of my if statements I can set a session value and change the text of the label.
My code in Page_Load():
' Check for cookies:
If Not Page.IsPostBack Then
Response.Cookies("TestCookie").Value = "ok"
Response.Cookies("TestCookie").Expires = DateTime.Now.AddMinutes(1)
End If
If Page.IsPostBack Then
If Request.Cookies("TestCookie") Is Nothing Then
Session("AuthenticationerrorMessage") = "COOKIES ARE BLOCKED!<br /> Browser cookies must be allowed to access this site. Please allow Javascript and cookies from this site in your web browser settings."
lblAuthenticationerrorMessage.Text = "COOKIES ARE BLOCKED!<br /> Browser cookies must be allowed to access this site. Please allow Javascript and cookies from this site in your web browser settings."
'Response.Redirect("~/NoAccess.aspx")
Else
Session("AuthenticationerrorMessage") = "Cookies Are Not Blocked."
Response.Cookies("TestCookie").Expires = DateTime.Now.AddDays(-1)
End If
'Else
' If Request.Cookies("TestCookie") Is Nothing Then
' Session("AuthenticationerrorMessage") = "Cookies Are Not Blocked - SPOCK."
' Response.Cookies("TestCookie").Expires = DateTime.Now.AddDays(-1)
' Else
' Session("AuthenticationerrorMessage") = "COOKIES ARE BLOCKED!<br /> Browser cookies must be allowed to access this site. Please allow Javascript and cookies from this site in your web browser settings - SPOCK."
' End If
End If
'(From this point onward, I can set the label text or set session variables just fine.)
Does this sound familiar to anyone?
TIA.

New Topic/Question
Reply




MultiQuote




|