Solved

asp.net & windows nt login name

Posted on 2007-11-27
7
1,379 Views
Last Modified: 2013-12-23
hey guys -

i've read a lot of people asking questions on this topic and i can't get any of their solutions to make sense to me.

right off, i'll ask - i have an asp.net website (c# backend). i'm trying to return the logged in user name (windows NT name) to my code. my IIS site is set up via anon auth.

is there any way that i can make this happen? here's a snippet that just returns an empty field for the username.

thanks guys!!


string userName = HttpContext.Current.User.Identity.Name.ToString(); 

        string[] username = new string[10];

        username = userName.Split('\\');

        userName = username[1].ToString();

        int wellid = 0;

        

        //open up connection to server

        String conString = GetConnectionString();

        TextBox1.Text = userName;

        if (Request.QueryString["add"] != null)

        {

            wellid = int.Parse(Request.QueryString["add"].ToString());
 

            try

            {

                SqlConnection connDB = new SqlConnection(conString);

                connDB.Open();

                SqlCommand cmdDB = connDB.CreateCommand();
 

                cmdDB.CommandText = "INSERT INTO MAP.USERSELECTION (userid, welloid) select '" + userName +

                            "'," + wellid;

                cmdDB.ExecuteNonQuery();

                connDB.Close();

                TextBox1.Text = "Item added to your list! You can close this browser!";

            }

            catch { }

        }

Open in new window

0
Comment
Question by:sclaple
7 Comments
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 20363142
Enable Integrated windows Authentication for your website in IIS
0
 

Author Comment

by:sclaple
ID: 20363164
is that the only way to do it? does that mean i have to be intranet to run it?
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20363272
1. Set <authentication mode="Windows"/> in your web config. check that the mode is set to Windows.
2. You can get the login name by using Request.ServerVariables("LOGON_USER")
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 20363274
If you want to get the Windows NT username you have to enable integrated windows authentication,It can be a internet or Intranet.Both will work fine
0
 

Author Comment

by:sclaple
ID: 20363299
if it is internet, my users will have to input a username/password that authenticates with the server hosting the site, right?
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 20363373
If you have exposed to internet then no need for your users to input the username/password
0
 
LVL 37

Accepted Solution

by:
Bing CISM / CISSP earned 500 total points
ID: 20364456
> my IIS site is set up via anon auth.

it is by design, if you do allow anonymous authentication and windows authentication at the same time. not only HttpContext.Current.User.Identity.Name property, other server variables such as AUTH_USER and REMOTE_USER also return an empty string.

as per MS KB article Q306359, you need to deny access to the anonymous user in the <authorization> section of the Web.config file, or use windows authentication only in the Web.config file. for more information, please read the following KB articles. Q306359 gives the resolution step by step.

PRB: Request.ServerVariables("LOGON_USER") Returns Empty String in ASP.NET
http://support.microsoft.com/kb/306359

PRB: Request.ServerVariables("LOGON_USER") Returns Empty String
http://support.microsoft.com/kb/188717

hope it helps,
bbao
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

10 Experts available now in Live!

Get 1:1 Help Now