locked
HttpCookie Read/Write problem RRS feed

  • Question

  • User1626053192 posted

    Hi,

    I've been searching a solution for this problem but i couldn't have one. By the way i can't understand the reason of my problem.

    The problem is: 

    My web application has a login page and gets logged user id from cookie. It worked before but 5-6 days ago because of something changed it didn't worked with IE. Now it doesn't work with any browser.

    I can see the cookie in Chrome. When looked with Internet Explorer Developer Tool sometimes the cookie written but still can't read by IE

    Here is my code

                      

                    string uId = "userID";
                    DateTime expireDate = DateTime.Now.AddDays(3);
                    HttpContext.Current.Response.Cookies["cookieName"]["uID"] = uId;
                    HttpCookie aCookie = new HttpCookie("cookieName");
                    
                    aCookie.Values["uID"] = uId;
                    aCookie.Path = "/";
                    aCookie.Expires = expireDate;
                    aCookie.HttpOnly = false;
                    aCookie.Domain = "domainname.com";
                    aCookie.Name = "cookieName";
                    HttpContext.Current.Response.Cookies.Add(aCookie);
    
    

     

    This web.config cookie tag

    <httpCookies domain=".domainname.com" httpOnlyCookies="false" requireSSL="false" />

    My web app is on Windows Server 2008 R2 BTW

    Wednesday, September 21, 2011 4:05 PM

All replies

  • User2037636850 posted

    hi bratupetre,

    I think this could be your IE8 dev tool problem, have you tired update your dev server with latest windows/IE updates?

    some people say that delete your browser history & cookies will help.

    i don't think there is anything wrong with your code, unless you can't read your cookie info from

    Request.Cookies

    hope it helps

    James

    Wednesday, September 21, 2011 4:59 PM
  • User1626053192 posted

    Hi James,

    I've tried with many PC's and many browser like IE 8-9, Chrome, Firefox, Safari, Opera. Sometimes login process completed without a problem but generally can't login because can't seting or reading cookie

    This is my request code:

                if (HttpContext.Current.Request.Cookies["cookieName"] != null)
                {
                    System.Collections.Specialized.NameValueCollection UserInfoCookieCollection;
    
                    UserInfoCookieCollection = HttpContext.Current.Request.Cookies["cookieName"].Values;
         
    
                    userID = HttpContext.Current.Server.HtmlEncode(UserInfoCookieCollection["uID"]);
     
                }
    Wednesday, September 21, 2011 5:09 PM
  • User1626053192 posted

    This is the scenario

    > trying to log in

    > SetCookie method triggered

    > End of SetCookie method there are two cookies "cookieName" and "ASP.NET SessionId"

    > GetCookie method triggered

    > There is only "ASP.NET SessionId" and session value still same

    Wednesday, September 21, 2011 5:35 PM
  • User2037636850 posted

    Hi,

    can you try remove these two line from web.config and your code, and see if you can read your cookie now?

    <httpCookies domain=".domainname.com" httpOnlyCookies="false" requireSSL="false" />
    aCookie.Domain = "domainname.com";

    I suspect it has something to do with domainname.com you entered. If above works, now try put them back but without "." in front of your domain property in web.config. just put domainname.com for wildcard domain

    Let me know how it goes

    James

    Wednesday, September 21, 2011 5:54 PM
  • User1626053192 posted

    Tried but still same :(

    Thursday, September 22, 2011 12:46 AM