Solved

web page thinks logged on user = "NETWORK SERVICE"

Posted on 2010-09-14
2
336 Views
Last Modified: 2012-05-10
I've created the method below to return the name of the user logged onto the PC.  ex:  john.doe

Works great when running from my own PC.  But when we put the code on our server and run it, the method returns a value of "NETWORK SERVICE" regardless of who runs the web page from their PC.

I need to know who is logged onto the site because that is used in the functionality of the site (ex:  record who made changes to data, etc.)

Thanks in advance for help,

Eric
public static string GetWindowsName()
  {
      string domainUser;
      string[] NameArray;

domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
      
NameArray = domainUser.Split('\\');

NameArray = User.Identity.Name.Split('\\');

return NameArray[1];
  }

Open in new window

0
Comment
Question by:Eric3141
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 total points
ID: 33672286

Hi,
The following code  "System.Security.Principal.WindowsIdentity.GetCurrent().Name" is used to what user the thread is executing as.

Please take a look at impersonation in this tech article. - http://support.microsoft.com/kb/306158

To correct this, you will need to configure the application to impersonate the Windows user who is accessing it by adding the following element after the authentication element in the Web.Config:

<identity impersonate="true"/>

If you do not set impersonate to true then the worker process runs as the Network Service or ASPNET account, depending on your version of IIS.

Cheers, Hades666
0
 
LVL 2

Author Comment

by:Eric3141
ID: 33708547
Worked great - thanks!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question