Developer forum

Forum » Development » redirection from dw page to another URL

redirection from dw page to another URL


Reply

Hi all


We need to have a page in our DW solution, where another webpage on the internet is loaded inside our solution from DW.


 


Does anyone know some code or other stuff I can use in order to do so?


 


 


Replies

 
Nicolai Høeg Pedersen
Reply
btp@gaincom.dk wrote:


Hi all




We need to have a page in our DW solution, where another webpage on the internet is loaded inside our solution from DW.




 




Does anyone know some code or other stuff I can use in order to do so?




 




 



Will  an iframe do the trick?:



 


Or do you need to fetch the html og the website on the server and display the HTML as module output on a paragraph?

 
Reply
np wrote:

btp@gaincom.dk wrote:





Hi all








We need to have a page in our DW solution, where another webpage on the internet is loaded inside our solution from DW.








 








Does anyone know some code or other stuff I can use in order to do so?








 








 






Will  an iframe do the trick?:







 




Or do you need to fetch the html og the website on the server and display the HTML as module output on a paragraph?


 


_______________________


 


I want to display the HTML as module output on a paragraph



 
Nicolai Høeg Pedersen
Reply

Hi


 


This is a class taken from the SEO module - it will fetch a website over the internet and give you the HTML:


 


Usage


 


Dim response As HttpData = HttpData.getHtmlFromUrl("http://www.dynamicweb.dk")


Dim html As String = response.Html


 


 


The httpdata class:


 


Imports System.Net


Imports System.Threading


Imports System.IO


Imports System.Text


Public Class HttpData


Private _Url As String


Private _RequestStartTime As DateTime


Private _RequestEndTime As DateTime


Private _Response As HttpWebResponse


Private _Html As String


Private _ThreadId As Integer


Private _Error As String


Public Property Url() As String


Get


Return _Url


End Get


Set(ByVal Value As String)


If Value.IndexOf("http://") < 0 Then


Value = "http://" & Value


End If


_Url = Value


End Set


End Property


Public ReadOnly Property RequestStartTime() As DateTime


Get


Return _RequestStartTime


End Get


End Property


Public ReadOnly Property RequestEndTime() As DateTime


Get


Return _RequestEndTime


End Get


End Property


Public ReadOnly Property RequestTime() As Double


Get


Dim ts As New TimeSpan(Me.RequestEndTime.Ticks - Me.RequestStartTime.Ticks)


Return ts.Milliseconds / 1000


End Get


End Property


Public ReadOnly Property Response() As HttpWebResponse


Get


Return _Response


End Get


End Property


Public ReadOnly Property Html() As String


Get


Return _Html


End Get


End Property


Public ReadOnly Property [Error]() As String


Get


Return _Error


End Get


End Property


Public Property ThreadId() As Integer


Get


Return _ThreadId


End Get


Set(ByVal Value As Integer)


_ThreadId = Value


End Set


End Property


Public Sub SetResponse(ByVal WebResponse As HttpWebResponse)


_Response = WebResponse


Dim ReceiveStream As Stream


Dim encode As Encoding


Dim sr As StreamReader


'Base.w(WebResponse.CharacterSet)


'For Each dimmer As System.Net.HttpResponseHeader In WebResponse.Headers


' base.w(dimmer.)


'Next


ReceiveStream = WebResponse.GetResponseStream()


'encode = System.Text.Encoding.GetEncoding("utf-8")


encode = System.Text.Encoding.GetEncoding(WebResponse.CharacterSet)


sr = New StreamReader(ReceiveStream, encode)


Dim read(256) As Char


Dim count As Integer = sr.Read(read, 0, 256)


Dim sb As New StringBuilder


Do While count > 0


Dim str As String = New String(read, 0, count)


sb.Append(str)


count = sr.Read(read, 0, 256)


Loop


_Html = sb.ToString


End Sub


Public Sub setError(ByVal errorText As String)


If errorText <> String.Empty Then


_RequestEndTime = Now


End If


_Error = errorText


End Sub


Public Sub New()


End Sub


Public Sub New(ByVal url As String)


Me.Url = url


End Sub


Public Sub Start()


_RequestStartTime = Now


End Sub


Public Sub Lookup()


Dim result As HttpWebResponse = Nothing


'Dim Response As New HttpData


Me.Start()


'Response.Url = url


Try


Dim req As HttpWebRequest


req = CType(WebRequest.Create(Me.Url), HttpWebRequest)


req.UserAgent = "DW Mozilla/5.0 (compatible;dw tool)"


req.Timeout = 3000


result = CType(req.GetResponse(), HttpWebResponse)


'Me.ThreadId = AppDomain.GetCurrentThreadId()


Me.ThreadId = Threading.Thread.CurrentThread.ManagedThreadId


Me.SetResponse(result)


Catch Exc As Exception


Me.setError(Exc.ToString)


Finally


If Not result Is Nothing Then


result.Close()


End If


_RequestEndTime = Now


End Try


End Sub


Public Delegate Sub LookupAsync()


Public Shared Function getHtmlFromUrl(ByVal url As String) As HttpData


'Dim result As HttpWebResponse


Dim Response As New HttpData


Response.Url = url


Response.Lookup()


Return Response


End Function


End Class

 
Nicolai Høeg Pedersen
Reply

The class as C#


 



using



using



using



using



public


{


private string _Url;


private DateTime _RequestStartTime;


private DateTime _RequestEndTime;


private HttpWebResponse _Response;


private string _Html;


private int _ThreadId;


private string _Error;


public string Url {


get { return _Url; }


set {


if (value.IndexOf("http://") < 0)


{


value = "http://" + value;


}


_Url = value;


}


}


public DateTime RequestStartTime {


get { return _RequestStartTime; }


}


public DateTime RequestEndTime {


get { return _RequestEndTime; }


}


public double RequestTime {


get {


TimeSpan ts = new TimeSpan(this.RequestEndTime.Ticks - this.RequestStartTime.Ticks);


return ts.Milliseconds / 1000;


}


}


public HttpWebResponse Response {


get { return _Response; }


}


public string Html {


get { return _Html; }


}


public string Error {


get { return _Error; }


}


public int ThreadId {


get { return _ThreadId; }


set { _ThreadId = value; }


}


public void SetResponse(HttpWebResponse WebResponse)


{


_Response = WebResponse;


Stream ReceiveStream;


Encoding encode;


StreamReader sr;


//Base.w(WebResponse.CharacterSet)


//For Each dimmer As System.Net.HttpResponseHeader In WebResponse.Headers


// base.w(dimmer.)


//Next


ReceiveStream = WebResponse.GetResponseStream();


//encode = System.Text.Encoding.GetEncoding("utf-8")


encode = System.Text.Encoding.GetEncoding(WebResponse.CharacterSet);


sr = new StreamReader(ReceiveStream, encode);


char[] read = new char[257];


int count = sr.Read(read, 0, 256);


StringBuilder sb = new StringBuilder();


while (count > 0) {


string str = new string(read, 0, count);


sb.Append(str);


count = sr.Read(read, 0, 256);


}


_Html = sb.ToString;


}


public void setError(string errorText)


{


if (errorText != string.Empty)


{


_RequestEndTime = Now;


}


_Error = errorText;


}


public HttpData()


{


}


public HttpData(string url)


{


this.Url = url;


}


public void Start()


{


_RequestStartTime = Now;


}


public void Lookup()


{


HttpWebResponse result = null;


//Dim Response As New HttpData


this.Start();


//Response.Url = url


try {


HttpWebRequest req;


req = (HttpWebRequest)WebRequest.Create(this.Url);


req.UserAgent = "DW Mozilla/5.0 (compatible;dw tool)";


req.Timeout = 3000;


result = (HttpWebResponse)req.GetResponse();


//Me.ThreadId = AppDomain.GetCurrentThreadId()


this.ThreadId = Threading.Thread.CurrentThread.ManagedThreadId;


this.SetResponse(result);


}


catch (Exception Exc) {


this.setError(Exc.ToString);


}


finally {


if ((result != null))


{


result.Close();


}


_RequestEndTime = Now;


}


}


public delegate void LookupAsync();


public static HttpData getHtmlFromUrl(string url)


{


//Dim result As HttpWebResponse


HttpData Response = new HttpData();


Response.Url = url;


Response.Lookup();


return Response;


}


}


class HttpData
System.Text;
System.IO;
System.Threading;
System.Net;

 

You must be logged in to post in the forum