1

I have done quite some researches on the topic, most answers I got is that cookie will NOT work on localhost since cookie expects the domain to contain at least 2 dots. But my question is, since ASP.NET WebSecurity class is able to set the authentication cookie from the server side, and javascript is able to set the cookie on client side when I am using localhost as domain. So there must be a way to do it, I would like to know how could it be done from the server side.

Update: Currently I am trying to do it with Java server.

Cookie tokenCookie = new Cookie("Token", token);
/*
will work if I include this line and use 127.0.0.1 to access my page
userNameCookie.setDomain("127.0.0.1");
*/
tokenCookie.setPath("/");
response.addCookie(tokenCookie);
return Response.ok().build();

I have no idea why there are two people trying to close this question as a duplicate. Please read people, I said I KNOW the reason why the cookie is not being set, but I know I could certainly do it and I want to know how!!!

Steve
  • 11,696
  • 7
  • 43
  • 81
  • Good news! Someone alread asked this and got an answer at [Why won't asp.net create cookies in localhost?](http://stackoverflow.com/questions/390219/why-wont-asp-net-create-cookies-in-localhost) – David Mar 24 '14 at 15:06
  • @DavidStratton as I said, they are all suggesting that you need two dots for the domain name, but ASP.NET's websecurity class can still set cookie on localhost without a problem. So there must be a way to do it. Note I am not using 127.0.0.1 but localhost:xxxx – Steve Mar 24 '14 at 15:09
  • @Steve maybe include some code on how you are setting cookie? I've never had an issue with this. – MikeSmithDev Mar 24 '14 at 15:11

0 Answers0