I have a question at least interesting! Gentlemen, it is possible to encapsulate a page "classic asp" inside a page "aspx"? The goal is to receive the output (text) of a legacy "classic asp" and places it inside a page "aspx". In this case (more specifically) I want to get the return of our "classic asp" as text, modify it and then return my "classic asp" inside the page "aspx". Can I do it when the request is by "GET", but by "POST" error occurs!

Apparently this problem is conceptual and has no way to capture the requests "POST" and redirect them to the page encapsulated. However, I wanted an opinion from an expert! My hypothesis is that if the requests via "POST" follow a pattern for any type of technology, it seems right that I can simply redirect that request "raw" to another page without worrying about its content.

private WebClient sessionWebClient
{
    get
    {
        if (Session["sessionWebClient"] == null)
        {
            Session["sessionWebClient"] = new WebClient();
        }
        return (WebClient)Session["sessionWebClient"];
    }
}

protected void Page_Load(object sender, EventArgs e)
{

    string retrieveHttpContentHolder = "";

    sessionWebClient.Headers.Clear();
    var headers = String.Empty;
    if (Page.Request.HttpMethod == "POST")
    {
        foreach (var key in Request.Headers.AllKeys)
        {
            headers += key + "=" + Request.Headers[key] + Environment.NewLine;
            sessionWebClient.Headers.Add(key.ToString(), Request.Headers[key].ToString());
        }
    }

    retrieveHttpContentHolder = RedirectRequests.PostUrl(sessionWebClient, Page.Request.HttpMethod,
    "http://localhost/goldendoc/login.asp", 
    Request.QueryString.ToString() +
    Request.Form.ToString());

    retrieveHttpContentHolder = retrieveHttpContentHolder.Replace("/goldendoc", "");
    retrieveHttpContentHolder = retrieveHttpContentHolder.Replace("image.asp", "image.aspx");
    retrieveHttpContentHolder = retrieveHttpContentHolder.Replace("login.asp", "login.aspx");

    Response.Write(retrieveHttpContentHolder);

}

public static string PostUrl(WebClient webClientHolder, string GETorPOST, string url, string what)
{

    byte[] byteArray = default(Byte[]);

    if (!string.IsNullOrEmpty(what) && GETorPOST == "GET")
    {
        url = url + "?" + what;
    }
    else if(GETorPOST == "POST")
    {
        Encoding.ASCII.GetBytes(what);
    }

    Byte[] bResult = default(Byte[]);

    if(GETorPOST == "POST")
    {
        bResult = webClientHolder.UploadData(url, GETorPOST, byteArray);
    }
    else if(GETorPOST == "GET")
    {
        bResult = webClientHolder.DownloadData(url);
    }

    Encoding objEncoded = Encoding.GetEncoding("utf-8");

    if (bResult != null)
    {
        return objEncoded.GetString(bResult);
    }

    return null;

}
Member Avatar for LastMitch

Apparently this problem is conceptual and has no way to capture the requests "POST" and redirect them to the page encapsulated. However, I wanted an opinion from an expert!

There's no experts! Noones perfect. It's called experience that what it matter the most.

Try this HttpClient-sample:

http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.