D
D
Dmitry Filandor2017-05-20 05:58:03
JavaScript
Dmitry Filandor, 2017-05-20 05:58:03

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 }); }
            }

.....

controller:
[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();
        }

I select a region, the cache is deleted, the main page is updated and I receive news from the selected region on it .... several minutes pass .... I update and have all the news again ... as before the choice .... and the cookie is still sitting. ... I
created a view, inserted the contents of the index page into it, I call it in the controller, but without the cache
public ActionResult testRegion()
        {
            return View();
        }

everything works on it testRegion .... why doesn't it work with the cache?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question