473,750 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Use rName;

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 9537
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.co m

"Joe" <th****@communi ty.nospam> wrote in message
news:9F******** *************** ***********@mic rosoft.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.Use rName;

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.Use rName;

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.Cur rent.User.Ident ity.Name or the ID on
the context. You can also access Thread.CurrentP rincipal.Identi ty.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:
<authenticati on mode="Windows"/>
<identity impersonate="tr ue"/>

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

protected void Session_Start(O bject sender, EventArgs e)
{
string login = WindowsIdentity .GetCurrent().N ame.Substring(
WindowsIdentity .GetCurrent().N ame.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.Use rName;

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
2516
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
9870
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 then use substring to parse out just the username. What I am trying to accomplish is getting the full name of the user by doing a search in Active Directory, but I am failing at every turn. This code:
4
5972
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 web.config file has authentication mode set to windows, and 'identity impersonate' is set to true. When I try and get the default.aspx page, IE returns an error page with an 'Access is denied.' error. (Even if I try direct from the webserver, logged...
0
1005
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: HttpContext.Current.User.Identity.Name; Can someone please tell me how I can achieve this same thing in managed c++ web service? Thanks a bunch!
2
7104
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 runat="server"> void Page_Load(Object Sender, EventArgs E) {
5
3680
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 error so please help me how can i access font file name by font name in windows vista or what change i have to do in following function to get the solution my function source code is givin below -
9
2651
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 to another location because it populates a Textbox in the user control page. Thanks Andrew
9
6053
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
10179
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 page and try to access that cookie. However, because I am using HttpContext.Current.User.Identity.Name to get the user id to know what that cookie name even is, I am having problems because apparently after 30 minutes...
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9344
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6810
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.