开发者

ViewStateUserKey sometimes doesn't validate

开发者 https://www.devze.com 2023-02-20 18:54 出处:网络
I have an application in ASP.NET that uses forms authentication. It has the following code. if (User.Identity.IsAuthenticated)

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消