By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

Why doesn't this work if in a UserControl?

P: n/a
This code comes directly from Microsoft's site:

Imports System.Security

Add the following code to the Page_Load event procedure:

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name

If I put the code in a webform (.aspx file) it works. But, if I try to
put it in a user control, I get the little blue squigly line under the
word User. (right before .Identity.Name). Why is that?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Because user is a property of the Page class. so in the page, when you are
doing

User.Identity.Name

it's really like doing

me.User.Identity.Name

and since me is an instance of Page, it inherits the User property.

A user control inherits from UserControl, instead of Page, and doesn't have
the property. To access the page's user from the user control do:
Page.User.Identity.Name ...as you can see while User isn't a property of
UserCOntrol, Page is...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jason ." <jr****@yahoo.com> wrote in message
news:OV****************@TK2MSFTNGP11.phx.gbl...
This code comes directly from Microsoft's site:

Imports System.Security

Add the following code to the Page_Load event procedure:

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name

If I put the code in a webform (.aspx file) it works. But, if I try to
put it in a user control, I get the little blue squigly line under the
word User. (right before .Identity.Name). Why is that?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2

P: n/a
Hello Karl Seguin,

The other way to go would be to reference:

HttpContext.Current.User.Identity.Name

--
Matt Berther
http://www.mattberther.com
Because user is a property of the Page class. so in the page, when
you are doing

User.Identity.Name

it's really like doing

me.User.Identity.Name

and since me is an instance of Page, it inherits the User property.

A user control inherits from UserControl, instead of Page, and doesn't
have the property. To access the page's user from the user control
do: Page.User.Identity.Name ...as you can see while User isn't a
property of UserCOntrol, Page is...

Karl

"Jason ." <jr****@yahoo.com> wrote in message
news:OV****************@TK2MSFTNGP11.phx.gbl...
This code comes directly from Microsoft's site:

Imports System.Security

Add the following code to the Page_Load event procedure:

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name
If I put the code in a webform (.aspx file) it works. But, if I try
to put it in a user control, I get the little blue squigly line under
the word User. (right before .Identity.Name). Why is that?

*** Sent via Developersdex http://www.developersdex.com *** Don't
just participate in USENET...get rewarded for it!

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.