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:
$(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)
$(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) {
},
Error: function () {
alert('An error occurred while loading customed Property.');
}
});
});
4- Users.ashx handlers code in 'Handlers/Permissions' which is as follows:
public void ProcessRequest(HttpContext context)
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
HttpCookie cookie = context.Request.Cookies.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.