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

finding the current user name accessing an ASP.NET page

P: n/a
Joe
This may actually be an IIS configuration issue but any help would be
appreciated.
I'd like to display some content based upon who the current user is that is
accessing an internal ASP.NET applciation. I am using the 2.0 framework. I
use the following syntax to retrieve the user name:

string username = Environment.UserName;

I use the 'username' variable to make comparisons and show the appropriate
content based upon the user. This works fine in a test enviornment (running
IIS 5.1). When I move it over to production (IIS 6.0) this code snipet
returns a single user called "NETWORK SERVICE" regardless of who or what
machine attempts to access the web page.

Any ideas on how I could return the appropriate user instead of "NETWORK
SERVICE" in a production Win2k3/IIS 6.0 enviornment?

Thanks for your help.
Mar 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Joe,

Assuming you have authentication set up correctly, why not use the User
property (which returns an IPrincpal implementation) on the Page class, or
on the HttpContext class?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe" <th****@community.nospam> wrote in message
news:9F**********************************@microsof t.com...
This may actually be an IIS configuration issue but any help would be
appreciated.
I'd like to display some content based upon who the current user is that
is
accessing an internal ASP.NET applciation. I am using the 2.0 framework. I
use the following syntax to retrieve the user name:

string username = Environment.UserName;

I use the 'username' variable to make comparisons and show the appropriate
content based upon the user. This works fine in a test enviornment
(running
IIS 5.1). When I move it over to production (IIS 6.0) this code snipet
returns a single user called "NETWORK SERVICE" regardless of who or what
machine attempts to access the web page.

Any ideas on how I could return the appropriate user instead of "NETWORK
SERVICE" in a production Win2k3/IIS 6.0 enviornment?

Thanks for your help.

Mar 10 '06 #2

P: n/a
Joe wrote:
This may actually be an IIS configuration issue but any help would be
appreciated.
I'd like to display some content based upon who the current user is that
is accessing an internal ASP.NET applciation. I am using the 2.0
framework. I use the following syntax to retrieve the user name:

string username = Environment.UserName;

I use the 'username' variable to make comparisons and show the appropriate
content based upon the user. This works fine in a test enviornment
(running IIS 5.1). When I move it over to production (IIS 6.0) this code
snipet returns a single user called "NETWORK SERVICE" regardless of who
or what machine attempts to access the web page.

Any ideas on how I could return the appropriate user instead of "NETWORK
SERVICE" in a production Win2k3/IIS 6.0 enviornment?

Thanks for your help.


That is because your web site is running under the NETWORK SERVICE account
on IIS6.0, whereas in the VS debugger it is running as you.

In your web you can use HttpContext.Current.User.Identity.Name or the ID on
the context. You can also access Thread.CurrentPrincipal.Identity.Name.
This would require that you do not allow anonymous access to your site,
otherwise the value will be null.
--
Tom Porterfield

Mar 10 '06 #3

P: n/a
Hi,
Any ideas on how I could return the appropriate user instead of "NETWORK
SERVICE" in a production Win2k3/IIS 6.0 enviornment?


First you have to configure your IIS , you go to the property of the
app/security and disable anonymous access.

Then in your web.config you have to set it to inpersonate and set the
authentication to windows:
<authentication mode="Windows"/>
<identity impersonate="true"/>

finally you get the login with WindosIdentity.GetCurrent , usually in the
session_Start:

protected void Session_Start(Object sender, EventArgs e)
{
string login = WindowsIdentity.GetCurrent().Name.Substring(
WindowsIdentity.GetCurrent().Name.LastIndexOf(@"\" )+1 );
Session["SystemUser"] = login;
}

I do remove the domain part.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 10 '06 #4

P: n/a
thanks all. I got it working. I used Ignacio's post to get it running.

"Joe" wrote:
This may actually be an IIS configuration issue but any help would be
appreciated.
I'd like to display some content based upon who the current user is that is
accessing an internal ASP.NET applciation. I am using the 2.0 framework. I
use the following syntax to retrieve the user name:

string username = Environment.UserName;

I use the 'username' variable to make comparisons and show the appropriate
content based upon the user. This works fine in a test enviornment (running
IIS 5.1). When I move it over to production (IIS 6.0) this code snipet
returns a single user called "NETWORK SERVICE" regardless of who or what
machine attempts to access the web page.

Any ideas on how I could return the appropriate user instead of "NETWORK
SERVICE" in a production Win2k3/IIS 6.0 enviornment?

Thanks for your help.

Mar 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.