tags:

views:

145

answers:

6

So here is what i am trying to achieve

When a user logs in and his password has expired, i redirect him a change password screen. I would like the user to change his password prior to going to other links in a menu

I want to redirect back to this changepassword.aspx when ever he attempts to leave, unless he changes his password

So how do I do this? and more importantly where?

Thanks for the help!

EDIT: I know we can use response.redirect, but it cant be used in the Unload operation

EDIT: ok i am not asking this right, i need help in keeping the user on the page - how do i do that and which part of the page [load, unload, etc]

A: 

Set a flag in the user's session indicating that they need to change their password, then check that flag from all your other pages and redirect them to the change-password page if necessary.

Mike Daniels
+6  A: 

Please don't do that. That kind of PITA UI is very irritating. Just expire their password and then fail their access if they don't change it.

Don't treat your users like children (unless they really are children and maybe not even then)

Edit: Made this a Community answer, as I'm just preaching not answering ;-)

Tim Jarvis
Unfortunately the client wants it that way, so if the user's password has expired then he wants them to change it before anything else.
thisismydisplayname
thanks for the point of view though :)
thisismydisplayname
The thing your client will need to have explaining, is that it's the user's perogative to do something else - if they just give up and turn off their machine, there is nothing you can do about that. Just be content that if their password has expired, they can't access anything else on your site - in the bad old days of the web, you could keep spawning new windows as a user shuts one down, but thankfully those days are mostly behind us. Sorry. As you've found out, the only "reliable" indication the user is going is the Unload event, and by then it's too late, unless pop-ups are enabled...
Zhaph - Ben Duguid
Also, you'll need some way to work out whether the unload event is fireing because the user has closed the browser, or because they have successfully changed their password, and are moving on to the next page - otherwise you'll end up spawning more pages as they try to continue.
Zhaph - Ben Duguid
+1  A: 
  1. Set a session var if they need to change their password
  2. On every pageload check for that session and if it exists (and they're not on the password change screen), redirect.
Oli
This is the simplest solution.
Rex M
No no no. Do it in Global.asax. Putting it in every page load event is reddiculous.
Boo
I really didn't mean the literal pageload event. Bad typo.
Oli
@boo you can put it on every pageload event from a module or base page class. This answer clearly leaves room for intelligent implementations. No reason to downvote.
Rex M
A: 

I'd set a variable in his session, then in your Global.asax Application_BeginRequest event check for the Session variable and redirect if needed.

Boo
+2  A: 

Explained: Forms Authentication in ASP.NET 2.0

"This module explains how forms authentication works in ASP.NET version 2.0. It explains how IIS and ASP.NET authentication work together, and it explains the role and operation of the FormsAuthenticationModule class."

In the web.config, I have the authorization section saying

<authorization>
  <deny users="?"/>
  <allow users="*"/>
</authorization>


<location path="ChangePassword.aspx">
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>
CodeToGlory
+1  A: 

We used to use a masterpage on our site and in the Page_Load event of that, we redirect the user to our changepassword.aspx page.

We also used (or abused, depending on your viewpoint) the Profile element of asp.net membership and simply set a MustChangePassword entry to true in it. It means that when they log-in, you can see if the MustChangePassword entry is set in their profile and redirect to the change password page. It certainly keeps them on the page.

People are right to suggest that sticking it in every page load is silly but the overhead is tiny to check one element in the users profile and you at least can force currently logged in users to change their password.

Neil Trodden