Tema: Web App
Pregunta: Como guarar en un archivo HTML el resultado de una página aspx.
Respuesta:
vb.net Cita: Dim mywebReq As WebRequest
Dim mywebResp As WebResponse
Dim sr As StreamReader
Dim strHTML As String
Dim sw As StreamWriter
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mywebReq = WebRequest.Create("http://localhost/pagina.aspx")
mywebResp = mywebReq.GetResponse()
sr = New StreamReader(mywebResp.GetResponseStream)
strHTML = sr.ReadToEnd
sw = File.CreateText(Server.MapPath("temp.html"))
sw.WriteLine(strHTML)
sw.Close()
Response.WriteFile(Server.MapPath("temp.html"))
End Sub
c# Cita: WebRequest mywebReq ;
WebResponse mywebResp ;
StreamReader sr ;
string strHTML ;
StreamWriter sw;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
mywebReq = WebRequest.Create("http://localhost/pagina.aspx");
mywebResp = mywebReq.GetResponse();
sr = new StreamReader(mywebResp.GetResponseStream());
strHTML = sr.ReadToEnd();
sw = File.CreateText(Server.MapPath("temp.html"));
sw.WriteLine(strHTML);
sw.Close();
Response.WriteFile(Server.MapPath("temp.html"));
}