Solved

web page thinks logged on user = "NETWORK SERVICE"

Posted on 2010-09-14
2
335 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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