Setting ViewStateUserKey gives me a “Validation of viewstate MAC failed” error

后端 未结 5 1902
清歌不尽
清歌不尽 2020-12-06 09:55

I have the following in my BasePage class which all my ASPX pages derive from:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);         


        
5条回答
  •  春和景丽
    2020-12-06 10:37

    OK - Im a year late to the conversation - but how is this the correct answer? This applies only in the case of authenticated users and using the ViewStateUserKey as the username is a lot easier to guess than a session id GUID.

    BTW if you want to 'fix' the code up top, use the Session ID, however you must set a session variable in order for the session id to stop from changing every time. Ex. Session["Anything"] = DateTime.Now

    ViewStateUserKey = Session.SessionID;
    

    This of course is assuming you are going to use sessions, otherwise you need some other key to use such as the username or any other guid kept in a cookie.

提交回复
热议问题