public IActionResult Demo() { var model = new CsrfModel { IsAuthenticated = CheckAuthentication() }; return(View(model)); }
public void Delete(int id) { try { CsrfModel csrf = new CsrfModel { PrivateDataId = id }; _myContext.Csrf.Attach(csrf); _myContext.Csrf.Remove(csrf); _myContext.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } }
public IActionResult Post([FromBody] CsrfViewModel value) { if (ModelState.IsValid) { CsrfModel csrf = new CsrfModel { PrivateData = value.PrivateData, PrivateDateTime = DateTime.Now }; _myContext.Csrf.Add(csrf); _myContext.SaveChanges(); return(Ok("New value was stored succesfull!")); } else { return(BadRequest("Storing the item has failed!")); } }
public IActionResult SomeDangerOperation() { Request.Headers.TryGetValue("Accept", out StringValues acceptHeader); bool isJson = acceptHeader.Contains("application/json"); if (isJson) { var model = new CsrfModel { IsAuthenticated = CheckAuthentication() }; return(Json(model)); } string imgFile = CheckAuthentication() ? "/csrf/Authenticated.png" : "/csrf/UnAuthenticated.png"; return(File(imgFile, "image/png")); }