asp.net cookie在localhost上安全失败

I am trying to make asp.net cookie secure like Response.Cookies["username"].Secure = true. Some reason these are failing. I mean after login I am setting this then new page is showing error "Page can not displyed".

Response.Cookies["username"].HttpOnly= true is working for all cookies. not Secure.

Is it because I am using on localhost? does it need https://?

The Secure property of an HttpCookie means that the cookie is only transmitted over SSL. So to test it you need to self-generate a certificate and have your site respond to https requests as well.