On my asp.net website I have membership functions enabled which require users to login.
I would like to store the username in the session data for a query which will be used once they have logged in.
On my login page I have the following code to store the session data but it does not work:
Session["UserName"] = System.Web.HttpContext.Current.User.Identity.Name;
The query will not load any results because the control parameter (session[username]) returns empty.
Can anyone suggest what could be the reason why its not working?
often the user info isn’t available until the next page load.
You may have to redirect to a “hop” page after login and redirect back to the page the user requested.
Here’s how to do it with MVC
Login:
Hop page: It’s at this point that the user info is actually available.