Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,
When i am trying to retrieve cookie from a handler file the HttpContex.Request.Cookie.Get("cookieName") always return null.

Let me explain about the code and design.
I have two folders in my project solution:
1- A folder named 'Account' that includes all my aspx pages.
2- A folder named 'Handlers' contains another folder named 'Permissions' that all my ashx handler files are in this folder
3- I have a aspx page named Default in Account folder and Users.ashx Handler in Permissions folder
Now in default.aspx i am making a cookie named 'State' in javascript jquery on unload event which is as follows:
JavaScript
$(window).unload(function () {
            document.cookie = "State=this is a test";
}); 

I want to call Users.ashx handler after creating cookie with jquery ajax as follows:
Complete code(create cookie and call the handler file)
JavaScript
$(window).unload(function () {
            document.cookie = "State=this is a test";
            $.ajax({
                Type: 'POST',
                url: '../Handlers/Permissions/Users.ashx',
                data: { ActionPage: 'TransportType', Action: 'SaveCustomedProperty', propertyItem: '34' },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                cache: true,
                success: function (data) {
                    //colModel = data.PropertyValue;
                },
                Error: function () {
                    alert('An error occurred while loading customed Property.');
                }
            });
}); 

4- Users.ashx handlers code in 'Handlers/Permissions' which is as follows:
C#
public void ProcessRequest(HttpContext context)
    {
     HttpRequest request = context.Request;
     HttpResponse response = context.Response;
     HttpCookie cookie = context.Request.Cookies.Get("State");//HttpContex.Request.Cookie.Get("State");
          string co = cookie.Value;
}

Creating cookie and calling Users.ashx in Default's jquery work perfectly but in Users.ashx ProcessRequest method context.Request.Cookies.Get("State") always return null although cookie exists; however when i am create Users.ashx in Account folder it works fine.
I think this problem happens cause of different namespase exists in these two files, i.e. Web.Application.NGWeb.Handler for Users.ashx & Web.Application.NGWeb.Account for Default.aspx.
any idea is truly appreciated.
Thanks in advance.
Posted
Updated 1-May-13 0:21am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900