I fix Cross-Site Request Forgery (CSRF). In OnInit method of masterpage:
if (requestCookie != null && Utility.GuidTryParse(requestCookie.Value, out requestCookieGuidValue))
{
_antiXsrfTokenValue = requestCookie.Value;
Page.ViewStateUserKey = _antiXsrfTokenValue;
}
Page.PreLoad += master_Page_PreLoad;
In master_Page_PreLoad I validate
if ((string)ViewState[AntiXsrfTokenKey] != _antiXsrfTokenValue || (string)ViewState[AntiXsrfUserNameKey] != (Context.User.Identity.Name ?? String.Empty))
{
logCSRF.Info("Error CSRF " + CurrentSession.CurrentUser.user_id);
Response.Redirect(Constants.DefaultPage.LoginPage);
}
After validate I reset antiXsrfTokenValue and value of cookie:
_antiXsrfTokenValue = Guid.NewGuid().ToString("N");
Response.Cookies[AntiXsrfTokenKey].Value = _antiXsrfTokenValue;
Exception thow "Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster."
Why has this exption?Resolve?
Thanks for help me!