Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Encapsulate a page "classic asp" inside a page "aspx"

eduardolucioaceduardolucioac Posts: 1Member
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.

Below I put some code snippets that I used in my attempts to illustrate.

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;

}
Sign In or Register to comment.