Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
what is the diffenernce between user.identity.name and session["username"]
Posted

Identity

You'll only be able to retrieve the identity of the person accessing the web app, if that person is logged in on the server. If the IIS authentication is turned off, then no authentication will be required, and therefore, no identity will be provided to the web app. The web app will have to know who you are, before it can say your name.

Session

you might be knowing that session variable has default scope of 20 minutes by default ,which we set on IIS server,we can change it according to need
so your session variable will be available for just 20 minutes ,so this session variable can be used to hold data for long time,i mean as long as your session is alive as per iss server setting
 
Share this answer
 
User.Identity.Name is the name of the current user
Session["username"] is what you make of it, ASP.NET doesn't use it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Aug-11 17:58pm    
You could have explained that Session works like an associative container (dictionary), can hold data by any arbitrary key. One can use any other key instead of "username"; only uniqueness of the key and match across pages matters. My 4.
--SA
Simon Bang Terkildsen 16-Aug-11 18:49pm    
Very true, I'm new to this "pass on your knowledge"-thing, a side I'm currently trying to improve. So thank you for pointing that out :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900