sclaple
asked on
asp.net & windows nt login name
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!!
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 { }
}
Enable Integrated windows Authentication for your website in IIS
ASKER
is that the only way to do it? does that mean i have to be intranet to run it?
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("L OGON_USER" )
2. You can get the login name by using Request.ServerVariables("L
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
ASKER
if it is internet, my users will have to input a username/password that authenticates with the server hosting the site, right?
If you have exposed to internet then no need for your users to input the username/password
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.