473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

finding the current user name accessing an ASP.NET page

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
4 9506
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: mickeyg | last post by:
i am going through the process of password protecting a directory using ..htaccess and .htpasswd Is there a function to get the user name? Thanks
4
by: Mike | last post by:
Greetings, I am writing an Intranet application in ASP.NET using VB.NET. I am obtaining the username of the user with: uName = User.Identity.Name, which is in the form of DOMAIN\username. I...
4
by: Nick | last post by:
I'm developing an intranet app, and want to get the current user name for logging purposes. I've turned off anonymous access, and turned on windows authentication in the IIS config. The apps...
0
by: Sharon McCarty | last post by:
Hi Everyone, I created a managed c++ web service and I would like to get the current user that is accessing the web service. This can be done in asp.net using c# by going:...
2
by: Abraham Andres Luna | last post by:
hello everyone, does anyone know why i can't access the HttpContext.Current.User.Identity.Name property in a .cs file? this is the index.aspx page: <%@ Page Language="C#" %> <script...
5
by: =?Utf-8?B?Qkw=?= | last post by:
Hello friends In c# 2005 I have written a function to access "font file name" by "Font name" and it is working fine in all the windows version other than vista, in vista it is throughing an...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
9
by: Victor | last post by:
Hi all Does anyone has any reference or examples about how to customize the httpcontext.current.user object to my own user object? Cheers Victor
4
by: Doogie | last post by:
Hi, I am using HttpContext.Current.User.Identity.Name to get a user id from a web application. I then use that as part of a name of a cookie I'm writing. 30 minutes later I do a refresh of this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.