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
Solved

asp.net & windows nt login name

Posted on 2007-11-27
7
1,419 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
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
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:
bbao 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

829 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