Friday, February 20, 2015

How to get Cookies reference is getting in ashx file

Here is how you can do it if you set Cookies in different pages. Below code will help you get Cookies in ASHX file

  public void ProcessRequest(HttpContext context)
        {
            context.Response.AddHeader("Pragma", "no-cache");
            context.Response.AddHeader("Cache-Control", "private, no-cache");

            if (context.Request.Cookies["UserID"] != null && 
                context.Request.Cookies["UserID"].Value != null 
                && context.Request.Cookies["UserID"].Value.Trim() != "")
            {
                UserID = Convert.ToInt32(context.Request.Cookies["UserID"].Value);
            }

            HandleMethod(context);
        }
Hope this helps !!