2

this works fine on my local site but as soon as i upload the site to my live server i get stem.NullReferenceException: Object reference not set to an instance of an object

on the first line of this:

if (!Page.User.Identity.IsAuthenticated)
{
    pnlSignIn.Visible = true;
    pnlSignOut.Visible = false;
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
phil
  • 61
  • 3
  • Can you attach the debugger, and then mouse-over the parts of that variable to see what is null? IE, check if Page is null, then is User is null, then if Identity is null. – Andrew M Dec 23 '10 at 13:24
  • 1
    Another question: Do you have a section in web.config for etc etc? Could you edit your queston and include that section of web.config? – Andrew M Dec 23 '10 at 13:27
  • Check if the IIS authentication is the same and correct. – Thea Dec 23 '10 at 13:40
  • 1
    it can be a duplicate of http://stackoverflow.com/questions/1990433/if-user-identity-isauthenticated-then-object-reference-not-set-to-an-instance – Thea Dec 23 '10 at 14:02

1 Answers1

5

You should use Request.IsAuthenticated instead of Page.User.Identity.IsAuthenticated.

Internally Request.IsAuthenticated will verify that the User and it's Identity are set (not null). You could do the same in your code, but why bother.

Marnix van Valen
  • 13,265
  • 4
  • 47
  • 74