Is this a Major Bug in C# ASP.NET Generic Handler Redundant Variables?

78 views Asked by At

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"

1

There are 1 answers

3
JohanP On

It is expected behaviour if you use cookies for Session. When you look at the source code for HttpRequest, you can see that Cookies get added to the Params collection:

private void FillInParamsCollection() {
        _params.Add(this.QueryString);
        _params.Add(this.Form);
        _params.Add(this.Cookies);
        _params.Add(this.ServerVariables);
}