Link to home
Start Free TrialLog in
Avatar of ianinspain
ianinspain

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I meant in my last post to do that in your masterpage load event.   Sorry if I wasn't clear on that.
Avatar of ianinspain
ianinspain

ASKER

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
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......
Make sure you are using/importing the correct libraries
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;

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.
are those your using statements for the masterpage?
yes in the master page and in a page that inherits from a master page..
Try the line "Me.User" see if that is recognized in the masterpage.
hi strickdd,

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

then try using "Page.User" see if that works.
Thanks everyone for there comments, the search continues about why Page. is used... but i am happy that it works....

thanks again

Ian
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.