get user identity in user control

G

Guest

I've created a simple function to capture the userid when a page is hit. I
can include this function in the page load using if not ispostback, but i'd
perfer to place it in the page load event of the user control i have created
for navigation. However, the user object does not appear to be available. Is
there a way around this? or am i doing something wrong?

(additional note: i also tried putting it in the global.asax but get an
error.)
 
S

S. Justin Gengo

Kes,

Check your include files/references in the regular .aspx page. Whichever
object you're using to obtain user identity is being referenced by the .aspx
page, but not by the user control. Also, in case the object is already being
referenced by the user control (which is likely) try creating it via it's
full path name.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

I guess i was hoping the user control would have access to the user identity
after it was included on the page. this would save me from calling the
function (created as component) on each aspx page in the site. So far the
user is found on each page with out problem even when it does not exist (as
Null or blank). however, i can't help feeling i'm missing something.

page pg1.aspx has control uctrl1.ascx (as does all other pages on the site).
With out directly referencing pg1.aspx can i get the user identity?
thanks
kes

--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


S. Justin Gengo said:
Kes,

Check your include files/references in the regular .aspx page. Whichever
object you're using to obtain user identity is being referenced by the .aspx
page, but not by the user control. Also, in case the object is already being
referenced by the user control (which is likely) try creating it via it's
full path name.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Joined
Dec 31, 2007
Messages
1
Reaction score
0
HttpContext.Current.User.Identity.Name

Good day :veryprou: ,

I've done it before inside SqlSiteMapProvider.cs and it works; then I've used it later in one of my .ascx user control and it works too.

So just add the following to your string control or variable:

HttpContext.Current.User.Identity.Name

or

System.Web.HttpContext.Current.User.Identity.Name

example: String getusername = HttpContext.Current.User.Identity.Name;
 
Joined
Apr 2, 2008
Messages
3
Reaction score
0
Thanks to "mkaouri",

I've been in forums all day and your simple example worked perfect!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top