Abe Miessler
Abe Miessler

Reputation: 85126

Cookie not getting created when redirecting?

I have the following in my controller:

    public ActionResult Login(string email, string password)
    {
        /* 
           some stuff 
           ...
        */
        HttpCookie CustomerCookie = new HttpCookie("Customer");
        CustomerCookie.Values.Add("FirstName", Customer.FirstName);
        CustomerCookie.Values.Add("LastName", Customer.LastName);
        CustomerCookie.Values.Add("Email", email);
        CustomerCookie.Secure = true;
        Response.Cookies.Add(CustomerCookie);
        return RedirectToAction("OrderType", "Order");
    }

But for some reason when I look for the cookie it is nowhere to be found after the redirect. Based on this question I was assuming that the method above would work.

Can anyone see why my cookie is not being created here?

Upvotes: 1

Views: 630

Answers (1)

Kristofor
Kristofor

Reputation: 58

Some troubleshooting steps I would take:

  • Remove the redirect and just return an empty view and see if the cookie is there
  • Do not set Secure to true and see if that's the issue
  • Force a response flush to see if there's an action filter or something post action execution that's preventing the cookie from being returned in the response
  • Use fiddler to look at the actual http response for the cookie in case your browser is preventing cookies

Upvotes: 2

Related Questions