Answer the question
In order to leave comments, you need to log in
ASP mvc 5 why doesn't cookies + cache work?
Hello everyone, guys help solve the charade!
There is an index view:
.....
<div class="content-right-col-region-top">
<a href="@Url.Action("Region", "Home", new {Region = 0})"> Все /</a>
<a href="@Url.Action("Region", "Home", new {Region = 1})">Европа/</a>
<a href="@Url.Action("Region", "Home", new {Region = 2})">Запад</a>
</div>
.....
@* Лента новостей по странам*@
@{
var Coo = (Request.Cookies["Region"]);
if (Coo == null || Coo.Value == "0") { Html.RenderAction("GetNews", new { Region = 0}); }
else if (Coo.Value == "1") { Html.RenderAction("GetNews", new { Region = 1 }); }
else if (Coo.Value == "2") { Html.RenderAction("GetNews", new { Region = 2 }); }
}
.....
[OutputCache(Location = System.Web.UI.OutputCacheLocation.Any, Duration = 120)]
public ActionResult Index()
{
return View();
}
public ActionResult Region(int Region)
{
//добавить куку
HttpCookie cookie = new HttpCookie("Region"); ;
cookie.HttpOnly = false;
cookie.Value = Region.ToString();
cookie.Expires = DateTime.Now.AddMonths(36);
Response.Cookies.Add(cookie);
HttpResponse.RemoveOutputCacheItem(Url.Action("Index", "Home"));
Response.Redirect("https://times.club/");
return View();
}
public ActionResult testRegion()
{
return View();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question