We help IT Professionals succeed at work.

500pts: User.Identity.IsAuthenticated not available in Master page in Page_Load?

ianinspain
ianinspain asked
on
Medium Priority
688 Views
Last Modified: 2008-01-09
Hi there,

I have a master page and in teh code behind the User.Identity.IsAuthenticated  isn't available - well certainly intelisense doesn't recognise it..

Of course putting it in the page_load of a page that inherates from a master page seems ok but i want it in the master page as all my pages need this code

Is there an alternative?

Anyone have any ideas?

Thanks in advance

Ian
Comment
Watch Question

Commented:
In your page load event.. what happens if you call      Page.User.Identity.IsAuthenticated?    does that work?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Sorry I meant in my last post to do that in your masterpage load event.   Sorry if I wasn't clear on that.

Author

Commented:
ermm that seems to work.... why the page. needed?

Is it because of master pages, just interested in why it seems to work now......??

Thanks in advance

Ian

Author

Commented:
p.s. it does return False which is good... i haven't done my authentication yet... will do that now i presume i should get True....

strange why the standard User.Identity.IsAuthenticated doesn't seem to work though......

Must be related to master pages......

Commented:
Make sure you are using/importing the correct libraries

Author

Commented:
the correct libraries?

I have a standard USING structure that is created by default... But in a normal page (or page that inherits from master page) you can just use user.identity.isauthenticated but in a master page it doesn't seem to be available.. of course adding page at the front seems to work.. I am testing now.

My standard USING is the following which is added by VS 2005 by default in a master page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


and a normal page that inherits from a master page has these which seems to be the same...

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

Commented:
That is a good question about why it requires the Page call infront of it.  It might be because the MasterPage is sort of above the Page and not really part of it so you have to reference it first inside of a Master Page.

Commented:
are those your using statements for the masterpage?

Author

Commented:
yes in the master page and in a page that inherits from a master page..

Commented:
Try the line "Me.User" see if that is recognized in the masterpage.

Author

Commented:
hi strickdd,

this is VB.net isn't it? i am using c#

Commented:
then try using "Page.User" see if that works.

Author

Commented:
Thanks everyone for there comments, the search continues about why Page. is used... but i am happy that it works....

thanks again

Ian

Author

Commented:
Just incase anybody is interested, i did manage to find out why Page. is needed, this is from a person in a forum where i asked the question..

-----------
Because a master page is just a glorified user control, so it needs to know which page it's on (as would any other user control).

Of course, you can always go for HttpContext.Current.User.Identity.IsAuthenticated*, but that takes longer to type, so I don't tend to bother!

 

* Page.User is really just a friendlier reference to get to HttpContext.Current.User.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.