Madhav Sharma

Madhav Sharma

  • 880
  • 899
  • 39.2k

Getting "Error occurred during a cryptographic operation"

Apr 9 2020 3:19 AM
As I hosted my application in plesk cloud server and everything is fine but if I sit screen ideally for 10 min then it will show the error
 
Error occurred during a cryptographic operation.
 
I did not understand why it is showing error, please help me. 
 
Here is my global.ashx file code and controller code
  1. protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)  
  2.        {  
  3.            //HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];  
  4.            HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];  
  5.            if (authCookie != null)  
  6.            {  
  7.                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);  
  8.                LoginUserViewModel serializeModel = JsonConvert.DeserializeObject(authTicket.UserData);  
  9.                CustomPrincipal newUser = new CustomPrincipal(authTicket.Name);  
  10.                newUser.Id = serializeModel.Id;  
  11.                newUser.Email = serializeModel.Email;  
  12.                //newUser.Password = serializeModel.Password;  
  13.                newUser.FullName = serializeModel.FullName;  
  14.                newUser.FirstName = serializeModel.FirstName;  
  15.                newUser.LastName = serializeModel.LastName;  
  16.                newUser.Roles = serializeModel.Roles;       
  17.                HttpContext.Current.User = newUser;  
  18.            }  
  19.        }  
  1. namespace WebApp.Controllers  
  2. {  
  3.     public class AccountController : Controller  
  4.     {  
  5.         // GET: Account  
  6.         IUserRepository repo_user;  
  7.   
  8.         public AccountController(IUserRepository _repo_user)  
  9.         {  
  10.             repo_user = _repo_user;  
  11.         }  
  12.         public ActionResult Login()  
  13.         {  
  14.             return View();  
  15.         }  
  16.         public ActionResult UnAuthorize()  
  17.         {  
  18.             return View();  
  19.         }  
  20.   
  21.         [HttpPost]  
  22.         public ActionResult Login(LoginViewModel model)  
  23.         {  
  24.             if (ModelState.IsValid)  
  25.             {  
  26.                 //UserViewModel user = repo_user.ValidateUser(model);  
  27.                 LoginUserViewModel user = repo_user.ValidateUser(model);  
  28.                 if (user != null)  
  29.                 {  
  30.                     string data = JsonConvert.SerializeObject(user);  
  31.   
  32.                     FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, data, FormsAuthentication.FormsCookiePath);  
  33.                     string encTicket = FormsAuthentication.Encrypt(ticket);  
  34.                     HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);  
  35.                     Response.Cookies.Add(cookie);  
  36.   
  37.                     if (user.Roles.Contains("Admin"))  
  38.                     {  
  39.                         return RedirectToAction("Index""Home"new { area = "Admin" });  
  40.                     }  
  41.                     else if (user.Roles.Contains("Company"))  
  42.                     {  
  43.                         return RedirectToAction("Index""Home"new { area = "Company" });  
  44.                     }  
  45.                     else if (user.Roles.Contains("User"))  
  46.                     {  
  47.                         return RedirectToAction("Index""Home"new { area = "User" });  
  48.                     }  
  49.                     else if (user.Roles.Contains("Franchisee"))  
  50.                     {  
  51.                         return RedirectToAction("Index""Home"new { area = "Franchisee" });  
  52.                     }  
  53.                 }  
  54.                 else  
  55.                 {  
  56.                     TempData["UserLogin"] = " Userid or Password does not exist, please try with other credential";  
  57.                 }  
  58.             }  
  59.             return View();  
  60.         }  
  61.         public ActionResult SignOut()  
  62.         {  
  63.             FormsAuthentication.SignOut();  
  64.             return RedirectToAction("Login");  
  65.         }  
  66.     }  
  67. }  

Answers (2)