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
ianinspainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jjardineCommented:
Sorry I meant in my last post to do that in your masterpage load event.   Sorry if I wasn't clear on that.
0
ianinspainAuthor 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
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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

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

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

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

thanks again

Ian
0
ianinspainAuthor 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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.