Last post Jan 15, 2014 09:42 PM by AndyW2009
Jan 14, 2014 11:49 PM|AndyW2009|LINK
I have a web app for which I need to create a manual login control. In this controls login method I am doing an FormsAuthentication.SetAuthCooking followed by a Response.Redirect - this works for logging in the user, however, the LoginView displays "Hello,
!" and is missing the users name.
When the the user is logged in I would like to use the LoginView to display the logged in user. It appears that I need to create an identity for this (HttpCurrent.Context.User is not yet set). Does anyone know how I can set the identity so that the LoginView
will display the logged in user?
I assume that it is also required that I set the IsAuthenticated property of the new identity as well?
Jan 15, 2014 01:11 AM|A2H|LINK
You can try with the below code
<asp:LoginView ID="Loginview1" runat="server" EnableViewState="false">
<%= Page.User.Identity.Name %>
Jan 15, 2014 03:04 PM|AndyW2009|LINK
Hi, much thanks for your reply.
I have tried that but my issue is that the Identity is empty (so Identity.Name is null). I am aware that I need some additional wireup between setting the auth cookie and doing the page redirect but I am not sure exactly what it needs to be.
I have tried setting HttpContext.Current.User with a new GenericPrinciple(new FormsIdentity(ticket)) as I needed to add some roles, however, the name of the user is still remaining unset.
Jan 15, 2014 09:42 PM|AndyW2009|LINK
I managed to get this working by moving the call to FormsAuthentication.SetAuthCookie to just before the response.redirect which is the last statement in the method. I have the feeling I may have been clearning out the username field somehow which was
why I was not seeing a username but the login was working.
Also checked in the page_load of the master page and the identity.isauthenticated flag is being set to true as well as getting the name parameter set, so the loginview is correctly displaying now.