为什么当用户注销时,authenticateRequest 会在页面上触发?
我的目标是在用户进行身份验证时写入 cookie。 我们正在使用一个蹩脚的框架,它隐藏了其源代码和事件模型,因此当我使用他们的登录控件时,我无法在其上设置会话超时!
不管怎样,我试图在用户登录时写入一个cookie,然后在后续页面浏览时刷新cookie过期时间(滑动过期)。
所以我想我最初可以在 global.asax 中的 Application_AuthenticateRequest 期间创建 cookie,但即使用户尚未登录,它似乎也会触发。
情况应该是这样吗?
My goal is to write a cookie when the user authenticates. We are using a crappy framework that hides its source code and event model so when I use their login control I can't set a session timeout on it!
Anyhow, I am trying to write a cookie when the user is logged in, and then refresh the cookie expire time on subsequent page views (sliding expiration).
So I figured I could initially create the cookie during Application_AuthenticateRequest in teh global.asax but that seems to be firing even when the user hasn't signed in yet.
Is that suppose to be the case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Application_AuthenticateRequest 在每个请求上都会触发,但如果您使用表单身份验证并且用户尚未登录,您会发现 HttpContext 的 User 属性(通过全局应用程序类文件中的 this.User 访问)的计算结果为 null ,而如果用户登录,它将评估为 IPrincipal 对象。
因此您可以执行以下操作:
其中 authCookieName 是 cookie 名称。
The Application_AuthenticateRequest fires on each request, but if you are using forms authentication and the user haven't logged in yet, you will find that the User property of the HttpContext (accessed through this.User in the global application class file) evaluates to null, while it will evaluate to an IPrincipal object if the user is logged in.
So you can do something like this:
where authCookieName is the cookie name.
是的。 每次请求访问网站时都会发生 Application_AuthenticateRequest。 AuthenticateRequest 以及进行身份验证还将检查并返回页面是否要进行授权。 某些页面需要从身份验证和授权检查中排除,例如登录页面。
根据您的情况,您还应该检查页面并排除登录序列中涉及的页面。
Yes. The Application_AuthenticateRequest will occur everytime a request hits the website. The AuthenticateRequest as well as doing the authentication will also check and return if Authorisation is to happen for the page. Some pages need to be excluded from authentication and authorisation checks, such as the login page.
For your situation you should also check the page and exclude those that are involved in the login sequence.