5 Replies - 2886 Views - Last Post: 20 August 2012 - 01:36 PM Rate Topic: -----

#1 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 100
  • Joined: 07-February 06

Login.aspx variable data disappearing

Posted 09 August 2012 - 02:00 PM

I've been going around in circles with this, but I think I've got this narrowed down.
(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.

Is This A Good Question/Topic? 0
  • +

Replies To: Login.aspx variable data disappearing

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,083
  • Joined: 05-April 11

Re: Login.aspx variable data disappearing

Posted 12 August 2012 - 03:10 AM

You change the label text but after that you redirect the user to a different page. That is not going to work.
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")


Was This Post Helpful? -1
  • +
  • -

#3 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 100
  • Joined: 07-February 06

Re: Login.aspx variable data disappearing

Posted 14 August 2012 - 07:19 AM

Thanks for the reply.

First, the redirect is commented out. Second, the redirect doesn't work anyway.
Was This Post Helpful? 0
  • +
  • -

#4 code_junkie83  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 62
  • Joined: 17-June 09

Re: Login.aspx variable data disappearing

Posted 14 August 2012 - 10:43 AM

Do you really need the If Page.IsPostback on the second block of code? Are you getting in there the second time through? That seems like the reason it would not be setting the label properly, if it never got back into that code.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Login.aspx variable data disappearing

Posted 15 August 2012 - 05:14 AM

Your problem is this. You are writing a cookie, but you aren't allowing it to be sent to the browser. You are creating the cookie, then immediately checking it. You need to create the cookie, then do a redirect to your own page(so that it sends the cookie to the browser), then check if the cookie exists.

http://forums.asp.net/t/1044823.aspx
Was This Post Helpful? 0
  • +
  • -

#6 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 100
  • Joined: 07-February 06

Re: Login.aspx variable data disappearing

Posted 20 August 2012 - 01:36 PM

Thanks for the replies!

@code_junkie83: removing the IF ISPostBack doesn't seem to change anything.

@eclipsed4utoo: Quite right, but the problem is that the authentication process is hijacking things. If you've got cookies blocked, the system automatically keeps you on Login.aspx, so I can't check on a receiving page.

I have found something very creepy out, though. When I authenticate with blocked cookies, I stay on Login.aspx and there is no special message displayed. When I mistype the password, my warning message appears!

Can anybody see why it would act this way??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1