Check if a cookie value exists and then redirecting
Posted on 2010-11-17
Hi - I need a bit of help with cookies. I created a cookie called UserCookie that hold two values; a UserID and a Name.
I want to check if one of the two values exists before a specific page loads. If it doesn't exist I want to redirect them to the login page. I wrote something like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.Cookies("UserCookie")("UserID") Is Nothing Then
However, when my page loads I get the following error:
Object reference not set to an instance of an object.
How can I fix this problem?