ViewStateUserKey 有时无法验证
我在 ASP.NET 中有一个使用表单身份验证的应用程序。它有以下代码。
if (User.Identity.IsAuthenticated)
ViewStateUserKey = User.Identity.Name;
单步执行,我看到这段代码在每个页面加载时执行。当登录用户请求该页面时,ViewStateUserKey 会填入他们的用户名。如果您让页面一直等到表单身份验证超时,则用户将不再登录,并且回发在验证视图状态时会失败,因为名称现在为空。但是我注意到,如果我在屏幕上放置其他按钮,并且回发,即使在身份验证超时后,它也不会失败。每次超时都会出现这个错误吗?
I have an application in ASP.NET that uses forms authentication. It has the following code.
if (User.Identity.IsAuthenticated)
ViewStateUserKey = User.Identity.Name;
Stepping through I see this code executes on each page load. When a logged in user requests the page, the ViewStateUserKey is filled in with their username. If you let the page sit till forms auth times out, the user is no longer logged in, and a post back fails on validation of the viewstate because the name is now null. However I have noticed if I put other buttons on the screen, and the post back, it doesn't fail, even after authentication has timed out. Should this error every time it times out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这是在 page_init 之后加载的 page_init 视图状态中,那么你的答案很简单。这里有 Pagelifecycle 的描述,加载视图状态发生在页面初始化事件之后。所以视图变量在 page_init 中不可用
your answer is easy if this is in page_init viewstate loads after page_init. Here you have the description of the Pagelifecycle which describes, that the load view state happens after the page init event. so the view variables are not available in the page_init