Redirecting in an SecurityEvents.Authenticate.Execute event redirects user to login page

Ismail Mohd asked on March 15, 2019 10:58

Hi, I'm trying to redirect new users to the "Change Password" page. I've implemented a custom handler to handle this "SecurityEvents.Authenticate.Execute" event. Below is a portion of my code...

public override void Init(){
    SecurityEvents.Authenticate.Execute += Authentication_Execute;
}
private void Authentication_Execute(object sender, AuthenticationEventArgs e){
    var ui = (UserInfo) e.User;
    if (ui.LastLogon == DateTime.MinValue){
        URLHelper.Redirect("/CMSModules/MyDesk/MyProfile/MyProfile_ChangePassword.aspx?tabselemid=m_c_plc_lt_ctl00_VerticalTabs_l_t_tabsElem");
    }
}

But when the redirect is executed, the user is redirected to the login page with the redirect url appended to the url as ReturnURL.

So it seems that the user was redirected when the system doesn't yet recognize the user as an authenticated user?

How do I redirect the user then?

Correct Answer

Brenden Kehren answered on March 15, 2019 17:57

Create a page in your content tree with a custom change password webpart on it. Then simply redirect them to that page and make sure it's not secured or restricted. You will have to create your own custom webpart because you can't simply change a passwword without knowing the user account your changing the password for. So I'd suggest passing a hash or some GUID from the users account to change the password for to your page with the custom webpart on in your custom event.

1 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.