I have tried everything I can think of, but nothing is working for me. Just
when I read an example and I'm 95% of the way done, I can't actually update
the xml file. :<
(http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=96)
Very disappointing as the reason I came to aspx was for it's supposed
simplicity to JSPs. :< I hope I wasn't wrong.

I've tried the following and all I get is this.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.


These are the lines I've tried:

testing.Text = Thread.CurrentPrincipal.ToString();



testing.Text = User.ToString();



testing.Text =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();



The aspx compiles so I'm assuming I have all the right imports, what could I
be doing wrong? The reason why I'm on this ride is I can't actually update
the XML file, if you know how I can do that it would be greatly appreciated!
:>

Re: how do you get current username in aspx? by Flip

Flip
Tue Jan 25 22:05:41 CST 2005

> be doing wrong? The reason why I'm on this ride is I can't actually
> update
I think I got it to work, but in a very weird way. I had to give Modify
access to the Users account, but I don't understand. A few websites I read
said to add write privileges to the ASPNet user and other say to the
IUSR_machinename user. What's with all the different solutions?

Any thoughts to help clear up my foggy mind would greatly be apprectiated.
Thank you.



Re: how do you get current username in aspx? by Matt

Matt
Wed Jan 26 01:59:15 CST 2005

Hello Flip,

Given your examples below, I am assuming youre using Windows Authentication.

It should be as simple as: HttpContext.Current.User.Name

--
Matt Berther
http://www.mattberther.com

> I have tried everything I can think of, but nothing is working for me.
> Just when I read an example and I'm 95% of the way done, I can't
> actually update the xml file. :<
> (http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=96
> ) Very disappointing as the reason I came to aspx was for it's
> supposed simplicity to JSPs. :< I hope I wasn't wrong.
>
> I've tried the following and all I get is this.
>
> Exception Details: System.NullReferenceException: Object reference not
> set to an instance of an object.
>
> These are the lines I've tried:
>
> testing.Text = Thread.CurrentPrincipal.ToString();
>
> testing.Text = User.ToString();
>
> testing.Text =
> System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()
> ;
>
> The aspx compiles so I'm assuming I have all the right imports, what
> could I be doing wrong? The reason why I'm on this ride is I can't
> actually update the XML file, if you know how I can do that it would
> be greatly appreciated! :>
>



Re: how do you get current username in aspx? by Paul

Paul
Wed Jan 26 08:52:06 CST 2005

On Tue, 25 Jan 2005 23:05:41 -0500, "Flip" <!REMOVE_ME!phenry_w@hotmail.com> wrote:

¤ > be doing wrong? The reason why I'm on this ride is I can't actually
¤ > update
¤ I think I got it to work, but in a very weird way. I had to give Modify
¤ access to the Users account, but I don't understand. A few websites I read
¤ said to add write privileges to the ASPNet user and other say to the
¤ IUSR_machinename user. What's with all the different solutions?
¤
¤ Any thoughts to help clear up my foggy mind would greatly be apprectiated.
¤ Thank you.
¤

The solution would depend upon the type of authentication that is implemented and whether
impersonation is being used. The following should help explain the different scenarios:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetap05.asp


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)

Re: how do you get current username in aspx? by Flip

Flip
Wed Jan 26 09:15:09 CST 2005

> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetap05.asp
Thank you Paul for the link, I'm reading it now! :>



Re: how do you get current username in aspx? by Flip

Flip
Wed Jan 26 09:11:38 CST 2005

> Given your examples below, I am assuming youre using Windows
> Authentication.
Yup, I was trying the forms authentication but having some problems. So
before I work out those bugs, I thougt I would use the Windows
authentication to get the app up and running first.

> It should be as simple as: HttpContext.Current.User.Name
Thank you, I'll try that again tonight! :> Any ideas on why those other
ones wouldn't work? I got them from the web and thought they would be easy
enough to get to work.

Thanks.



Re: how do you get current username in aspx? by Flip

Flip
Sat Jan 29 12:34:35 CST 2005

Howdy. I tried the following lines and to my astonishment, nothing is
printed in the Trace for the username. What is happening here?

Trace.Write("username='" + HttpContext.Current.User.Identity.Name.ToString()
+"'");

Trace.Write("usertostring=" + HttpContext.Current.User.ToString());

Trace.Write("type=" + HttpContext.Current.User.GetType().FullName);



THis gives this in the trace output.

username='' 0.003853 0.003408
usertostring=System.Security.Principal.WindowsPrincipal 0.004247
0.000394
type=System.Security.Principal.WindowsPrincipal




Re: how do you get current username in aspx? by Paul

Paul
Mon Jan 31 08:34:09 CST 2005

On Sat, 29 Jan 2005 13:34:35 -0500, "Flip" <!REMOVE_ME!phenry_w@hotmail.com> wrote:

¤ Howdy. I tried the following lines and to my astonishment, nothing is
¤ printed in the Trace for the username. What is happening here?
¤
¤ Trace.Write("username='" + HttpContext.Current.User.Identity.Name.ToString()
¤ +"'");
¤
¤ Trace.Write("usertostring=" + HttpContext.Current.User.ToString());
¤
¤ Trace.Write("type=" + HttpContext.Current.User.GetType().FullName);
¤
¤
¤
¤ THis gives this in the trace output.
¤
¤ username='' 0.003853 0.003408
¤ usertostring=System.Security.Principal.WindowsPrincipal 0.004247
¤ 0.000394
¤ type=System.Security.Principal.WindowsPrincipal
¤
¤

That doesn't look like valid syntax to me. Are you trying to retrieve the first and last name of the
user?


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)

Re: how do you get current username in aspx? by Flip

Flip
Mon Jan 31 09:32:35 CST 2005

> That doesn't look like valid syntax to me. Are you trying to retrieve the
> first and last name of the
> user?
Howdy. I'm just trying to see something more than a null actually. Not
trying to be flippant, sorry, I just expected to see some text that made
sense to me, something like ASPNET or IUSR_machinename, annonymou or even my
own name, but nothing comes out and when I query the object I get nulls. :<
If it's the wrong syntax, I would have hoped Visual Studio would have given
me a compile error. :< I'm not sure what I'm doing wrong?

OH, the numbers coming up in that cut'n'paste is the cut'n'paste from the
Trace window in html that's outputted with the page, and I put the single
quotes to try to figure out if there was something, anything there.



Re: how do you get current username in aspx? by Paul

Paul
Mon Jan 31 12:01:54 CST 2005

On Mon, 31 Jan 2005 10:32:35 -0500, "Flip" <[remove_me]phenry_w@hotmail.com> wrote:

¤ > That doesn't look like valid syntax to me. Are you trying to retrieve the
¤ > first and last name of the
¤ > user?
¤ Howdy. I'm just trying to see something more than a null actually. Not
¤ trying to be flippant, sorry, I just expected to see some text that made
¤ sense to me, something like ASPNET or IUSR_machinename, annonymou or even my
¤ own name, but nothing comes out and when I query the object I get nulls. :<
¤ If it's the wrong syntax, I would have hoped Visual Studio would have given
¤ me a compile error. :< I'm not sure what I'm doing wrong?
¤
¤ OH, the numbers coming up in that cut'n'paste is the cut'n'paste from the
¤ Trace window in html that's outputted with the page, and I put the single
¤ quotes to try to figure out if there was something, anything there.
¤

Well, that doesn't help me understand what you're after. ;-)

The first Trace statement is valid and should return the domain and user ID. The second and third
statements are syntactically invalid. Perhaps this isn't immediately reflected because you're using
C#.


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)