Hi friends,
I am creating an application that takes current logged in user and displays on the page itself. for this I am getting the user name in PageLoad function by using this.User.Identity.Name and then storing the value in a hidden variable for aspx page. I am using this hidden variable to display the name of the user. I am using Windows authentication for this.
Now problem that I am getting is that when multiple user launch the application from different machine and if they click simultaneously, name of one user appears on the paged displayed on the machine of other user.
Say-- user A launch from his maching so he should get "Welcome User A" in his page, and user B launch from his own machine and he should get "Welcome user B". But when both user A and User B launch the application simultaneously ... both User A and B get "Welcome User A".
Please help me out on this, I have tried getting user name with Request.ServerVariables["REMOTE_USER"] as well but of no use
. This is a very strange situation.
Ya one more thing. I am using MSAccess in backend for storing some of the user data which also I am accessing.
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
Hi, are you using a shared function in your code behind by any chance? Can you show your code?
Regards
Smcoxon
No Gem is ever polished without some friction.
![]() |
0 |
![]() |
Hi, here is the code ...
public partial class Level_2 : System.Web.UI.Page
{
//UNIQUE level code for each page.
private const string LEVEL_CODE = "VERSION-ONE-LEVEL-TWO";
private checkAnswer objCheckAnswer;
private LoadUnloadData objDataRecorder;
private string strUserName;
private bool isLevelFreezed = false;
protected void Page_Load(object sender, EventArgs e)
{
//string strLoginUser = this.User.Identity.Name;
string strLoginUser = Request.ServerVariables["REMOTE_USER"];
//string strLoginUser = HttpContext.Current.User.Identity.Name;
if (!strLoginUser.Equals(string.Empty))
{
strUserName = strLoginUser.Remove(0, 11);
objDataRecorder = new LoadUnloadData();
//Get values of timers
int[] aryTimerValues = objDataRecorder.loadTimers(strUserName, LEVEL_CODE);
//Store the values in hidden variable as required by client side page.
hdnLevelTime.Value = Convert.ToString(aryTimerValues[0]);
hdnTotalTime.Value = Convert.ToString(aryTimerValues[1]);
if (aryTimerValues[2] == 1)
{
isLevelFreezed = true;
hdnIsLevelFreezed.Value = "1";
}
else
{
isLevelFreezed = false;
hdnIsLevelFreezed.Value = "0";
}
hdnUserName.Value = strUserName;
hdnLevelID.Value = LEVEL_CODE;
}
else
{
Response.Redirect("ErrorPage.aspx");
}
}
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
Hi, I cant see any issues with this code but this code isn't the code that reads the logged in username from the hdnUsername hidden field value to display it on an aspx page? Can you show the code that reads the hdnUsername value for display?
The way I approach this is to get the user name when the user logs in using the Login Controls Login1_LoggedIn event and the Membership.GetUser() method. Once I've retrieved the required user information I store it in Session state and retireve it from Session state whenever I need to display the user information on an aspx page.
Regards
Smcoxon
No Gem is ever polished without some friction.
![]() |
0 |
![]() |
this.User.Identity.Name and then storing the value in a hidden variable for aspx page. I am using this hidden variable to display the name of the user. I am using Windows authentication for this.
May be i am misunderstanding your question...But
Why are you storing value this.User.Identity.Name in a hiddenVariable ?
/GuruBhai
![]() |
0 |
![]() |
My aim is to display windows logged in user name on each page. The user is not shown any login window but the current logged in windows user name only is taken as his identity. What would be best approach for this ? Shall I call this on the very first page and store in state management?? or should I check on each page the name of the user as I am doing now??
But even if I go for any other approach, I would surely want to know the reason of why this is going wrong ... ???
The code for ASPX page is here
function window.onload()
{
varTotalTime = document.getElementById('hdnTotalTime').value;
varLvlTime = document.getElementById('hdnLevelTime').value;
document.getElementById('divUserName').innerHTML = document.getElementById('hdnUserName').value;
if( document.getElementById('hdnIsLevelFreezed').value == "1")
{
document.getElementById('divTimers').style.display = "none";
document.getElementById('divMessages').style.display = "block";
document.getElementById('divUserMessage').innerHTML = "<p>You have already cleared this level</p>";
}
else
{
startTimer();
}
}
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
My aim is to display windows logged in user name on each page.
Just use User.Identity.Name to get the logged-in username which you can get on any page....hidden field is not at all needed
and if you think you don't want to show the user in domainname\username format ... grab the username from the string
yes you can use Session instead of hiddenField
/GuruBhai
![]() |
0 |
![]() |
Again your Javascript code for reading the hidden fields looks OK. Going back to your Page_Load event that initially gets the user identity, try reusing the line of code:
string strLoginUser = this.User.Identity.Name; and change it to: strLoginUser = Page.User.Identity.Name; I know 'this' should work but...
Also, I'd start to look at the IIS settings. Take a look at this article, it might help: http://www.eggheadcafe.com/articles/20050703.asp
When user A and user B login simultaneously and user B is displayed as user A, what happens if you refresh user B's aspx page that runs the Page_Load event and code that gets the username? Does it then display correctly?
You should be able to use hidden fields, Session state, User.Identity, Cookie or any other method you chose or create for holding the logged in users identity.
Regards
Smcoxon
No Gem is ever polished without some friction.
![]() |
0 |
![]() |
Hi Guru,
The problem is not in the hidden field, and even if I dont use hidden field the problem that I am getting still persists. Please see my first post again to understand my problem. I am able to get the user name on every page by callilng User.identity.name. But when I launch the hosted ASP application from 3-4 different machines and if say 2 users simultaneously opens same page, page on the screens of both the use shows same name that is either of User A or user B.
Please help me if you have any idea what can be the reason....
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
Hi Smcoxon,
I made the change as you suggested, from "this" to "Page" but still having the same problem.
. I am looking into the link that you have provided and will let you know is that is of any help for me. But I am on ther verge of smashing my system for this problem ... not able to make out in any way why this is not working.
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
Hi,
I am still getting the problem
. Tried everything that comes to my mind . . the document also didn't help much .... still am struck at that point only. I am not able to find out the cause for this problem, cant even trace whats going wrong.
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
smcoxon:
When user A and user B login simultaneously and user B is displayed as user A, what happens if you refresh user B's aspx page that runs the Page_Load event and code that gets the username? Does it then display correctly?You should be able to use hidden fields, Session state, User.Identity, Cookie or any other method you chose or create for holding the logged in users identity.
Yes on refresh it displays correctly. I tried using Session variable also but still getting that problem. And also I don't want to pass anything in query string.
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |
Hi Ashwani,
This is wierd! The only thing I can think of is that for some reason your IIS server and Windows authentication system is providing your aspx page with the incorrect information as a result of similtaneous logins. This could be a timing, a config setting or slow process. I'm really not sure.
As suggested in my last reply. What happens if you click on the browser refresh for the user with the incorrect information displayed? Does it then show correctly?
Regards
Smcoxon
No Gem is ever polished without some friction.
![]() |
0 |
![]() |
Hi Ashwani,
Take a read through this msdn article on Windows authorisation and Impersonation:
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity_members.aspx
http://msdn.microsoft.com/en-us/library/ms998358.aspx
I feel this is the area to look closer at and I think you might need to use the WindowsIdentity Class to get the correct information you need. Hope it helps.
Regards
smcoxon
Regards
Smcoxon
No Gem is ever polished without some friction.
![]() |
0 |
![]() |
Thanks Smcoxon,
I'll go through this and will let you know my finding
.
---------------------------------------------
Ashwani
---------------------------------------------
100% of the shots you don't take don't go in.
---------------------------------------------
![]() |
0 |
![]() |