public ActionResult Index(string word) { _anagramsModel = new AnagramsViewModel(); if (word != null) { _anagramsModel.Word = word; string ip = HttpContext.Connection.RemoteIpAddress.ToString(); UserSearchLogModel userLog = new UserSearchLogModel(ip, word, null) { UserIP = ip, SearchDate = DateTime.Now }; _usersRepository.AddUserLog(userLog, word); try { _anagramsModel.Anagrams = _anagramsService.GetAnagrams(word, ip); } catch (Exception ex) { _anagramsModel.ErrorMessage = ex.Message; } CookieOptions cookieOptions = new CookieOptions(); cookieOptions.Expires = DateTime.Now.AddMinutes(10); string searchHistory = Request.Cookies["searchHistory"]; if (searchHistory == null) { searchHistory += $"{word}"; } else { searchHistory += $",{word}"; } Response.Cookies.Append("searchHistory", searchHistory, cookieOptions); } return(View(_anagramsModel)); }