Asp.Net CSRF Step 1: Add this code in master page, if there is no master page than add it in page. //This is code is to generate the random token protected void Page_Init(Object sender, EventArgs e) { if (!IsPostBack) { var pageName = Path.GetFileName(HttpContext.Current.Request.Url.AbsolutePath); var pageToken = pageName + "_ID"; RandomNumberGenerator rng = new RNGCryptoServiceProvider(); var tokenData = new byte[32]; rng.GetBytes(tokenData); var token = Convert.ToBase64String(tokenData); ...