In "C# Generic Handler", Session Variables and Input Params are becoming Duplicate or Redundant.
In C#,
if there is already a Session["X"] variable and
if input to iHttpHandler is "X", then
HttpContext.Current.Request.Params["X"] is
returning concatenated string of both Session and Input FormData from Ajax.
It is not distinguishing the difference.
I was sending data to "c# Generic Handler" from Ajax with FormData("X", "V").
Session already has the variable as "X", Say, Session["X"] is "Z";
in JS:
function f(ipaddr) {
var formData = new FormData();
formData.set("X", "V");
var url = window.location.origin + "/api/generichandlerapi.ashx";
$.ajax({
type: 'post',
url: url,
data: formData,
dataType: "json",
success: function (response) {
}
});
}
Inside Handler:
string C;
Session["X"] = "Z";
C = HttpContext.Context.Request.Params["X"];
C is supposed to have only "V"
but returning
"V,Z"
It is expected behaviour if you use cookies for
Session. When you look at the source code forHttpRequest, you can see thatCookiesget added to theParamscollection: