dear friends,
I am new to asp.net with C#.
My requirement is getting system login user id while page loading and displaying user detail based on fetched userid.
I have used the following methods in code behind part:
1. Request.UserHostName;
2. Request.ServerVariables["AUTH_USER"] ;
3. Request.ServerVariables["LOGON_USER"] ;
4. System.Web.HttpContext.Current.User.Identity.Name;
5. Environment.GetEnvironmentVariable("USERNAME").ToString();
6. User.Identity.Name
7. this.Request.LogonUserIdentity.Name;
8. System.Security.Principal.WindowsIdentity.GetCurrent().Name;
9. System.Environment.ExpandEnvironmentVariables("%username%");
10. dynamic wshell = Server.CreateObject("WScript.Shell");
string test = wshell.ExpandEnvironmentStrings("%username%");
Everything giving expected output. But after deploying that file in server and executing the deployed file it is giving blank outputs and server names. but not my expected output (user id).
I am suffering with this problem for the past 3 days. any idea... please...
since code behind part is not giving my expected output. I have used the below clientscript method in javascript:
function get_user_id() {
var wshShell = new ActiveXObject("WScript.Shell");
document.getElementById('hiddenfield').value = wshShell.ExpandEnvironmentStrings("%USERNAME%");
alert(document.getElementById('hiddenfield').value);
}
called this function in onload event of the body tag. I am getting user id in popup alert box.
string X = hiddenfield.value; // <-- looking empty
but in my code behind part it is still empty. while seeing it in debug mode my page load event in code behind part is executing first then only scripts are executing.
So, via this method also I can't achieve my target. I am so confused what to do. Please help me.... :-(