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
- protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
- {
-
- HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
- if (authCookie != null)
- {
- FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
- LoginUserViewModel serializeModel = JsonConvert.DeserializeObject(authTicket.UserData);
- CustomPrincipal newUser = new CustomPrincipal(authTicket.Name);
- newUser.Id = serializeModel.Id;
- newUser.Email = serializeModel.Email;
-
- newUser.FullName = serializeModel.FullName;
- newUser.FirstName = serializeModel.FirstName;
- newUser.LastName = serializeModel.LastName;
- newUser.Roles = serializeModel.Roles;
- HttpContext.Current.User = newUser;
- }
- }
- namespace WebApp.Controllers
- {
- public class AccountController : Controller
- {
-
- IUserRepository repo_user;
-
- public AccountController(IUserRepository _repo_user)
- {
- repo_user = _repo_user;
- }
- public ActionResult Login()
- {
- return View();
- }
- public ActionResult UnAuthorize()
- {
- return View();
- }
-
- [HttpPost]
- public ActionResult Login(LoginViewModel model)
- {
- if (ModelState.IsValid)
- {
-
- LoginUserViewModel user = repo_user.ValidateUser(model);
- if (user != null)
- {
- string data = JsonConvert.SerializeObject(user);
-
- FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, data, FormsAuthentication.FormsCookiePath);
- string encTicket = FormsAuthentication.Encrypt(ticket);
- HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
- Response.Cookies.Add(cookie);
-
- if (user.Roles.Contains("Admin"))
- {
- return RedirectToAction("Index", "Home", new { area = "Admin" });
- }
- else if (user.Roles.Contains("Company"))
- {
- return RedirectToAction("Index", "Home", new { area = "Company" });
- }
- else if (user.Roles.Contains("User"))
- {
- return RedirectToAction("Index", "Home", new { area = "User" });
- }
- else if (user.Roles.Contains("Franchisee"))
- {
- return RedirectToAction("Index", "Home", new { area = "Franchisee" });
- }
- }
- else
- {
- TempData["UserLogin"] = " Userid or Password does not exist, please try with other credential";
- }
- }
- return View();
- }
- public ActionResult SignOut()
- {
- FormsAuthentication.SignOut();
- return RedirectToAction("Login");
- }
- }
- }