ASP.NET - Fire login onauthenticate event - Asked By dan scan on 08-Feb-13 03:04 PM

I am trying to use the built in login controls that come with a .net project, but I need to be able to automatically log a person in so that the Context.User.Identity.IsAuthenticated is set to true.

I am trying to force the page to login automatically when a username and password are present. How to I fire the built in login controls authenticate event.

Danasegarane Arunachalam replied to dan scan on 08-Feb-13 06:21 PM
You can call the event in the PageLoad Event as

          AuthenticateEventArgs = new AuthenticateEventArgs();
.Authenticated = true;
Login1_Authenticate(this, auth);

Where the Login1 is the login control name
dan scan replied to Danasegarane Arunachalam on 08-Feb-13 10:07 PM
I have tried to call that handler like you have shown.  But it does not seem to work as desired.  
I am setting the AuthenticateEventArgs.Authenticated to true. But upon checking I am still seeing context.user.identity.isauthenticated is still false.  

But if I allow the standard flow from the login control it works fine.  I put stop points in the function that handles the authenticate event.  So I know that it is firing both ways.   So why does one way set the isauthenticated while the other ignore it?

Danasegarane Arunachalam replied to dan scan on 11-Feb-13 12:29 AM
I think the Formauthentication cookie value is causing the issue. Set the Cookie value and have a try

Add this code after the

Login1_OnAuthenticate Method

FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie);