Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi

i need to do something as follows

In my web application when a user loged in through the login page i need to remember their name and wanna display their name in every page they are visiting (like hotmail does)

 

i tried 2 methodes to do this,

1 is, put name in the cookies when a user logged in and display that in each and every page . In Application_End clear the cookies

other method was to use a session variables

 

both this methods were woking fine

 

but my problem is the pages don't refresh properly

say i logged in as user A . First Time it is working fine and all the pages displays A. then i logged out and logged in as B. but still the name displays as A. if i press F5 and refresh it'll display B correctly.

 

i used " <meta http-equiv="Pragma" content="no-cache"> " to refresh the page too but still it's not comming as i want

 

so if anyboday have an idea about this pls help

i'm using .net C# environment to develop my web application

 

Thank you

Posted (edited)

When it comes to user handling the ideal solution in .NET is Forms Authentication.

 

Normally it creates an encrypted cookie containing the user name of the current user (again ideal for your needs).

And if you want to store other values as well (user id, first name, last name, address, what ever...) you can extend the class and add your own get/set properties.

 

THis wasn't and answer to your question (sorry for that) but with Forms Auth. everything comes free and you will not have to bother about the thing you described above.

 

Otherwise... how do you log out? By a button or by closing the browser window? If the latter is true, I think you must destroy the old cookie, NOT when the user signs out, but when he signs IN.

Edited by sharpcoder
Posted
The Label on which you are displaying the User Name have the property of EnableViewState set to True Make it To false and in the page load event of every page use the code to set the name of the user on this label. It works just fine.

Asif Raza Ashraf

Senior Software Engineer

Electronic Solutions Pakistan

Islamabad

Posted

hi all

thank u very much for replying me

i found a answer by my own

i set cookies expired as at minDateTime (least possible date) in the Application end

now it 's working fine

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...