Adding headers - WeOnlyDo Discussion board

Adding headers (wodSFTP / wodSFTP.NET / wodSFTPdll)

by Matt Crook, Friday, January 14, 2011, 05:08 (4823 days ago)

Hey, I am looking to add custom headers to my app/web server! How do you do this? I am using ASPX also.


here is some code
Private Sub web1_RequestDoneEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Server.WebRequestDoneArgs) Handles web1.RequestDoneEvent
Args.User.Response.Headers.Add( UpdaterVersion , Testing )
'Args.User.ExecuteASPX(web1.DocumentRoot, / , / , Web.config )

Args.User.ExecuteASPX()

If Args.User.Request.PageName.ToLower = status.aspx Then
'Args.User.Response.Body = Args.User.Response.Body.Replace( < my_ver > , My.Application.Info.Version.ToString)

End If
'Args.User.ExecuteASPX( C:UsersmattAppDataRoamingWeOnlyDoSampleswodWebServer.NETVB 5. With ASPXWebSite1 , / , / , web.config )
End Sub


am i missing something?

Matt

Re: Adding headers

by woddrazen, Friday, January 14, 2011, 10:12 (4822 days ago) @ Matt Crook

Hi Matt,


Can you please add it at end of RequestDone Event. After ExecuteASPX line.

Does it work like that maybe?

Let us know how it goes.


Regards,
Drazen

Re: Adding headers

by Matt Crook, Friday, January 14, 2011, 22:56 (4822 days ago) @ woddrazen

Nope, makes no differance :(

Now does it matter if in form load I have this?

web1.Port = 80
web1.DocumentRoot = C:UsersmattDocumentsVisual Studio 2010ProjectsWebApplication1WebApplication1
web1.DefaultPage = default.aspx
web1.Start()

Re: Adding headers

by woddrazen, Friday, January 14, 2011, 23:54 (4822 days ago) @ Matt Crook

Matt,


Can you please try something like this. This worked for me without any problem
[code] Dim WithEvents web1 As WeOnlyDo.Server.WebServer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
web1 = New WeOnlyDo.Server.WebServer

web1.DocumentRoot = AppPath() + \WebSite1
web1.DefaultPage = Default.aspx
Try
web1.Start()
Catch ex As Exception
MsgBox( There was an error: & ex.Message, vbOKOnly, Error )
End Try
End Sub

Private Sub web1_RequestDoneEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Server.WebRequestDoneArgs) Handles web1.RequestDoneEvent
Args.User.ExecuteASPX(AppPath() + \WebSite1 , / , / , web.config )

Args.User.Response.Headers.Add( test_name , test_value )
End Sub

Public Function AppPath() As String
AppPath = System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory).ToString).ToString
End Function[/code]
If problem persist, can you maybe explain how did you check if header was sent?


Drazen

Re: Adding headers

by Matt Crook, Saturday, January 15, 2011, 00:32 (4822 days ago) @ woddrazen

I use c_version.Text = Request.ServerVariables( all_raw ).ToString

and it shows everything except for the custom header

Re: Adding headers

by Matt Crook, Saturday, January 15, 2011, 08:12 (4821 days ago) @ Matt Crook

Matt,


Can you please try something like this. This worked for me without any problem
[code] Dim WithEvents web1 As WeOnlyDo.Server.WebServer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
web1 = New WeOnlyDo.Server.WebServer

web1.DocumentRoot = AppPath() + \WebSite1
web1.DefaultPage = Default.aspx
Try
web1.Start()
Catch ex As Exception
MsgBox( There was an error: & ex.Message, vbOKOnly, Error )
End Try
End Sub

Private Sub web1_RequestDoneEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Server.WebRequestDoneArgs) Handles web1.RequestDoneEvent
Args.User.ExecuteASPX(AppPath() + \WebSite1 , / , / , web.config )

Args.User.Response.Headers.Add( test_name , test_value )
End Sub

Public Function AppPath() As String
AppPath = System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory).ToString).ToString
End Function[/code]
If problem persist, can you maybe explain how did you check if header was sent?


Drazen


HTTP_CONNECTION:Keep-Alive, TE HTTP_ACCEPT:text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 HTTP_ACCEPT_CHARSET:iso-8859-1, utf-8, utf-16, *;q=0.1 HTTP_ACCEPT_ENCODING:deflate, gzip, x-gzip, identity, *;q=0 HTTP_ACCEPT_LANGUAGE:en-US,en;q=0.9 HTTP_HOST:localhost HTTP_REFERER:http://localhost/ HTTP_TE:deflate, gzip, chunked, identity, trailers HTTP_USER_AGENT:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.7.62 Version/11.00

this is all it returns

Re: Adding headers

by woddrazen, Saturday, January 15, 2011, 11:11 (4821 days ago) @ Matt Crook

Matt,


Can you maybe check this out using some other tool? I just tried with HttpFox (extension for FireFox) and my header is there.

You can my result here:
http://dl.dropbox.com/u/3621080/header.jpg


Drazen

Re: Adding headers

by Matt C, Wednesday, January 19, 2011, 08:51 (4817 days ago) @ woddrazen

Matt,


Can you maybe check this out using some other tool? I just tried with HttpFox (extension for FireFox) and my header is there.

You can my result here:
http://dl.dropbox.com/u/3621080/header.jpg


Drazen


Okay, I used your setup and it shows, however, can anyone tell me what is the best way to talk WebApp to WebServer and vise virsa?

Matt

Re: Adding headers

by wodDamir, Wednesday, January 19, 2011, 09:46 (4817 days ago) @ Matt C

Matt,

You can't. Basically, asp.net code isn't interpreted by the component, but is passed to .net engine. The output is returned and stored into Response object.

The only way to communicate to the webapp would be to change the request/response before actually sending it back to user.

Regards,
Damba