ASHX C # for each loop on POST vars

I have the following C # code snippet in an ASHX or Generic Handler file:

public override void ProcessRequest(HttpContext contexto)
{
    string destino = contexto.Request["destino"];

    string variables = "?";

    string valor = "";

    foreach (string nombre in contexto.Request.QueryString)
    {
        if (nombre == "destino")
        {
            continue;
        } // Fin del if.
        else
        {
            if (contexto.Request.QueryString[nombre] != "")
            {
                valor = contexto.Request.QueryString[nombre];

                variables += nombre + "=" + valor + "&";
            } // Fin del if.
        } // Fin del else.
    } // Fin del foreach.

    variables = variables.Substring(0, variables.Length - 1);

    if (destino != null && destino != "")
    {
        switch (destino)
        {
            case "coordenadasPorMunicipios":    contexto.Response.Redirect("./admon/coordenadasPorMunicipios/CoordenadasPorMunicipiosControl.ashx" + variables);
                                                break;
            case "departamentos":               contexto.Response.Redirect("./admon/departamentos/DepartamentosControl.ashx" + variables);
                                                break;
            case "municipios":                  contexto.Response.Redirect("./admon/municipios/MunicipiosControl.ashx" + variables);
                                                break;
            case "negocios":                    contexto.Response.Redirect("./admon/negocios/NegociosControl.ashx" + variables);
                                                break;
            case "paises":                      contexto.Response.Redirect("./admon/paises/PaisesControl.ashx" + variables);
                                                break;
            case "sectoresIndustria":           contexto.Response.Redirect("./admon/sectoresIndustria/SectoresIndustriaControl.ashx" + variables);
                                                break;
            case "sectoresIndustriaPorNegocio": contexto.Response.Redirect("./admon/sectoresIndustriaPorNegocio/SectoresIndustriaPorNegocioControl.ashx" + variables);
                                                break;
            case "tiposNegocioPorNegocio":      contexto.Response.Redirect("./admon/tiposNegocioPorNegocio/TiposNegocioPorNegocioControl.ashx" + variables);
                                                break;
            case "tiposNegocios":               contexto.Response.Redirect("./admon/tiposNegocios/TiposNegociosControl.ashx" + variables);
                                                break;
            case "usuarios":                    contexto.Response.Redirect("./admon/usuarios/UsuariosControl.ashx" + variables);
                                                break;
        } // Fin del switch.
    } // Fin del if.
} // Fin del método ProcessRequest.

It works great for GET vars, I mean those that are sent to the URL, but I want to do this for POST rollers.

I tried to make an HttpContext object for each of them, but I received a message stating that the HttpContext class does not have an Enumerator inmpelementation function.

Any idea how I can do this for GET and POST vars ??

Thanks for the help!

+3
source share
3 answers

Request.Form is what you are looking for, it is for POST variables

+2
source

Request.QueryString GET, Request.Form post. , Request.Params

+2

Request.Paramsgives you a set of forms, QueryString, Cookie, and Server Variables, which is probably too much, so you'll probably want to limit yourself to repeating just .Formsthat .QueryString.

0
source

Source: https://habr.com/ru/post/1770814/


All Articles