ASP.NET 会员密码过期
我正在使用 ASP.NET 成员资格来验证我的 Web 应用程序。 这对我来说非常有用。 我现在必须实现密码过期。
如果密码已过期,则应将用户重定向到 ChangePassword
屏幕,并且在不更改密码的情况下不应允许用户访问应用程序的任何其他部分。
有很多aspx页面。 如果密码已过期,一种解决方案可能是重定向到每个 aspx 的 ChangePassword
屏幕 OnInit
。 有没有其他的解决办法或者建议。
谢谢, 贾伊
I am using ASP.NET membership for the authentication of my web app. This worked great for me. I now have to implement password expiration.
If the password has expired the user should be redirected to ChangePassword
screen and should not be allowed access to any other part of the application without changing the password.
There are many aspx pages. One solution could be to redirect to the ChangePassword
screen OnInit
of every aspx if the password has expired. Is there any other solutions or recommendations.
Thanks,
Jai
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
除了csgero的回答,我发现你不需要在 ASP.Net 2.0 (3.5) 中显式为此事件添加事件处理程序。
您只需在
global.asax
中创建以下方法,它就会为您连接起来:Further to csgero's answer, I found that you don't need to explicitly add an event handler for this event in ASP.Net 2.0 (3.5).
You can simply create the following method in
global.asax
and it gets wired up for you:您可以在 global.asax 中为 HttpApplication.PostAuthenticateRequest 事件添加事件处理程序并在那里处理重定向。
You could add an event handler for the HttpApplication.PostAuthenticateRequest event in global.asax and handle the redirection there.
根据 Andrew 的回答,我发现您需要检查用户是否已经在更改密码页面上,否则他们会永远无法真正更改其密码,因此永远不要离开更改密码站点:
Further to Andrew's answer, I found you need to check that the user is not already on the change password page, or they will never be able to actually change their password, and hence never leave the change password site:
只需大约一个小时即可完成此操作,无需修改您的基本页面。 您需要执行的操作如下:
响应会员控件的
LoggingIn
事件Find在会员数据库中查找用户并获取
LastPasswordChangedDate
使用 TimeSpan,将其与当前日期进行比较并确定上次更改密码的时间是否超过了所需的天数。 我从 web.config 获取此值
如果过期,重定向到
ChangePassword
屏幕Just implemented this in about an hour, no need to modify your base page. Heres what you have to do:
Respond to the
LoggingIn
event of the membership controlFind the user in the membership database and get
LastPasswordChangedDate
Using a TimeSpan, compare this with the current date and decide if the password was last changed more than the requisite number of days ago. I get this value from web.config
If expired, redirect to the
ChangePassword
screen我来这里寻找解决方案,但我当前的技术是 ASP.NET MVC。 因此,为了帮助其他人:您可以扩展
AuthorizeAttribute
,并重写OnAuthorization
方法,如下所示:注意:我使用 T4MVC 来检索上面代码中的控制器和操作名称。
使用此属性标记除“
AccountController
”之外的所有控制器。 这样做,密码过期的用户将无法浏览该网站。这是我就该主题发表的一篇文章,其中有一些优点:
ASP.NET MVC 中的用户密码过期过滤器属性
I got here looking for a solution to this but my current technology is ASP.NET MVC. So to help others: you can extend the
AuthorizeAttribute
, and overrideOnAuthorization
method, like this:Note: I use T4MVC to retrieve the Controller and Action names in the code above.
Mark all controllers with this attribute except "
AccountController
". Doing so no user with an expired password will be able to surf the site.Here's a post I did on the subject with some bonus points:
User Password Expired filter attribute in ASP.NET MVC
我使用了上面的代码,只对其进行了轻微修改,以便使用 .NET 身份提供程序在 Asp.NET (4.5) MVC5 中实现。 把它留在这里给下一个人/女孩:)
I used the code from above and only slightly modified it to implement in Asp.NET (4.5) MVC5 using the .NET Identity Provider. Just leaving it here for the next guy/gal :)