Solved

web page thinks logged on user = "NETWORK SERVICE"

Posted on 2010-09-14
2
330 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
2 Comments
 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 total points
Comment Utility

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
Comment Utility
Worked great - thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now