[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

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
0
ianinspain
Asked:
ianinspain
  • 7
  • 4
  • 3
1 Solution
 
jjardineCommented:
In your page load event.. what happens if you call      Page.User.Identity.IsAuthenticated?    does that work?
0
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now