Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

web page thinks logged on user = "NETWORK SERVICE"

Posted on 2010-09-14
2
Medium Priority
?
344 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

598 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