How can I read the Expires of a cookie?

1

I have a cookie which is called C__COOK containing a value 1 what I need to do is to be able to read this cookie completely, I mean with this to its property Expires to be able to use its value in a conditional.

I have the following in my controller where I create the cookie

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Signin(LoginViewModel model)
{
    if ((model.User.ToString() == "usuario") &&
        (model.Pass.ToString() == "123123"))
    {
        FormsAuthentication.RedirectFromLoginPage(model.User, false);
        HttpCookie httpCookie = new HttpCookie("C__COOK");
        httpCookie.Expires = DateTime.Now.AddMinutes(5);
        httpCookie.Value = ProtectCookieMethod("1");
        HttpContext.Response.Cookies.Add(httpCookie);
    }
    else
    {
        ViewBag.Message = "Usuario incorrecto";
    }

    return View();
}

Then from my client by means of Ajax I made a request get to a method Valid which returns a json with a value bool .

public JsonResult Valid()
{
    if (HttpContext.Request.Cookies["C__COOK"] != null
        && HttpContext.Request.Cookies["C__COOK"].Value != null)
    {
        var x = Response.Cookies["C__COOK"].Expires.ToString();
    }

    return Json(new { isValid = true }, JsonRequestBehavior.AllowGet);
}

This should compare the expiration date if it is already expired or not and return a message to my client with a json of type bool . The problem is that when I retrieve the property Expires of the form Response.Cookies["C__COOK"].Expires.ToString(); it returns a date nothing to do with pure 0 and 1.

How can I recover this data?

    
asked by vcasas 05.07.2018 в 19:11
source

0 answers