Been banging my head against the wall for the last several hours. What the &^*% am I doing wrong.

Code to set the cookie

Response.Cookies["mydomain-LoginName"].Value = ((Login)sender).UserName;
                        Response.Cookies["mydomain-LoginName"].Expires = DateTime.Now.AddDays(30);

code to read the information back in

strLoginName = Request.Cookies["mydomain-LoginName"].Value;

Recommended Answers

All 3 Replies

first try

strLoginName = Server.HTMLEncode(Request.Cookies["mydomain-LoginName"].Value);

Are you not getting anything? Does your browser not accept cookies? Or only from certain paths? If it doesnt you wont get an error. Test with Request.QueryString["AcceptsCookies"] to find out.

I finally figured it out. It was the new Login object in asp.net 2.0. It never completes the response, just redirects to another page. Response never ends so cookie never got written.(or something like that) So I just passed it to the page I was redirecting to and had that page write it.

oh, it uses its own cookies. Set the expiration etc in the web config. Both sliding and absolute. They have it all built in. If you need the config stuff let me know :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.