473,772 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading ASP.NET Response Header

Hi,

I need to read (& store) all the custom response headers in an
HttpResponse. I am writing an HttpModule and hence do not know what
headers could have been added (but need to cache them for later use).
The only relevant methods that I can see are
AppendHeader/AddHeader(strin g, string) and ClearHeaders() both of
which are obviously useless to me. Is there any way of reading the
custom headers?

I also considered replacing the HttpResponse object with my own
wrapper that just passes me the headers which I can add later, but
HttpContext.Res ponse is read-only.

Surely this should be possible?

Thanks

jpg

ps. I have actually got it working currently, I am using reflection to
'bypass' the fact that the _customHeaders field is private, although
this is obviously not the best way to do it.
Nov 17 '05 #1
6 5449
"_jpg_" <go************ ***@xoxy.net> wrote in message
news:5e******** *************** ***@posting.goo gle.com...
Hi,

I need to read (& store) all the custom response headers in an
HttpResponse. I am writing an HttpModule and hence do not know what
headers could have been added (but need to cache them for later use).
The only relevant methods that I can see are
AppendHeader/AddHeader(strin g, string) and ClearHeaders() both of
which are obviously useless to me. Is there any way of reading the
custom headers?
Do you only mean the custom headers, or do you need to get all of them?
Also, do you need to get at headers added by someone else's code?

If all you need is custom headers, and if you don't need them from someone
else's code, then I'd suggest you create methods to replace
AppendHeader/AddHeader and ClearHeaders. The methods would capture the
custom headers and then call Response.Append/Add/ClearHeaders.


Surely this should be possible?
Maybe. Note that you can't get at all of the headers, since they don't
actually exist anywhere until after the request is complete over. And even
then they don't exist as a collection or anything.
ps. I have actually got it working currently, I am using reflection to
'bypass' the fact that the _customHeaders field is private, although
this is obviously not the best way to do it.


This method will break as soon as they change their implementation. And if I
were them, I'd change the implementation just out of spite, knowing that
someone is poking around in my internals. HttpContext is even sealed. That
should be a hint to you...
--
John Saunders
Internet Engineer
jo***********@s urfcontrol.com
Nov 17 '05 #2
Ideally I would like all the headers, or be able to set whatever I need
to so that I can modify a response object to recreate whatever the
previous one would have.

However, I cannot even see how I can get the custom headers that users'
code has added (via the Add/AppendHeader methods).

I cannot replace the Append/Add/ClearHeaders methods because to do that
I would need to replace the response object within the httpcontext (with
my wrapper), and this is readonly. I could provide my own methods on a
completely different object, but as I'm an HttpModule this is awkward,
and the whole point is that the developer does not need to change his
code.

The current caching modules must cache headers too, it's just that I
believe as they are in the same assembly they call a load of internal
methods.

I know my reflection method is bad but I cannot currently see any other
way around it.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3
"_jpg_" <de************ *************** **@xoxy.net> wrote in message
news:uy******** ******@tk2msftn gp13.phx.gbl...
Ideally I would like all the headers, or be able to set whatever I need
to so that I can modify a response object to recreate whatever the
previous one would have.


I believe the technical term for this is "SOL". :-(

I have written an HttpModule which can capture the complete request and
response - except for the response headers! When I got to that point in the
code, I found that they literally do not exist as a collection, and do not
exist in any fashion until after the request is completely over. Instead,
ASP.NET produces its headers by calling methods on a class provided by the
hosting environment.

Now, there's your one hope. If your code has to work in the completely
general case, give up now and save yourself the trouble. But if you can run
your code under your own host (i.e., your own web server), then you can
produce a hack to make this happen. I managed to do this by hacking a
version of Microsoft's Cassini web server (a part of the Web Matrix project
at http://asp.net/webmatrix/default.asp...ex=4&tabId=46). As it turns
out, this was a fairly nasty hack, involving the server setting something in
one of the server variables for the HttpModule to read to pass back to a
static method in the server - it was pretty gross.

Under no circumstances would I consider such a hack suitable for any
production purpose. For any such purpose, I'd say, "sorry, find another way
to do it". For instance, you might be better off writing a network sniffer
or a custom proxy server than to screw around with private fields which are
as likely as not to change in the next .n release, or even on a service pack
release. "private" really means, "none of your business".

Good Luck. You'll need it.
--
John Saunders
Internet Engineer
jo***********@s urfcontrol.com
Nov 17 '05 #4
Ok thanks for your help - my solution cannot require a modified web
server, which seems to me like more of a hack than mine!

I believe that the best solution for me will be to clone the whole
HttpResponse object (using reflection), and then clone it back over the
top of the new one. This should at least mean small changes such as
field renaming won't break it (yes I know calls to external
methods/deeper objects still could). I could support only specific
versions of the framework - and this method will be fine for all the
existing versions.

If Microsoft manage to break this down the line there are quite a few
other classes that I could use looking at the OutputCacheModu le - none
of which are actually public again :-( It's really starting to annoy me
how closed the .NET api is compared to J2SE. Most of the classes seem to
be internal, as well as the amount they have sealed...

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #5
"_jpg_" <de************ *************** **@xoxy.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Ok thanks for your help - my solution cannot require a modified web
server, which seems to me like more of a hack than mine!

I believe that the best solution for me will be to clone the whole
HttpResponse object (using reflection), and then clone it back over the
top of the new one. This should at least mean small changes such as
field renaming won't break it (yes I know calls to external
methods/deeper objects still could). I could support only specific
versions of the framework - and this method will be fine for all the
existing versions.


My immediate reaction is "you must be crazy". After calming down and
thinking about it for a while, I've decided to stick with my immediate
reaction.

It sounds like the problem you were asked to solve was, "get me all the
response headers for all the requests sent to this web site". It seems to me
that the solution is to "get the response headers from where they're meant
to be seen - in the HTTP header of the response". It would take a change in
the HTTP protocol to break _that_ code, whereas it would take only a sneeze
to break yours.
--
John Saunders
Internet Engineer
jo***********@s urfcontrol.com
Nov 17 '05 #6
I agree this would be the best place to retrieve them, however I must
store them & issue a redirect, and if they have already been sent then I
am too late. I can only achieve this if all requests go through some
kind of proxy, which is very likely to not make it transparent to the
asp.net pages.

I imagine I could do it if I implemented the whole thing in a ISAPI
filter, which I may look at, but it seems stupid to me that I can't do
it in the framework itself.

Why do you see the reflection approach as such a problem if it is always
bound to a specific version of System.Web.dll? Updating my code for the
next release would not be a problem.

jpp

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10425
by: Google Mike | last post by:
Gosh. I posted this earlier on Google Groups, but it didn't appear. Perhaps there was a problem at Google. Forgive me for posting it again. This time, I'll be more brief. Instead of using cookies, I want to play with HTTP headers in general because I heard you can use these to circumvent cookie security/cleaner type apps (which I consider silly, btw). I want to write custom headers like: TRACK_fullname: Google Mike
0
1248
by: Lata Neti | last post by:
I am trying to retrieve images from SQL server and display them on the client’s browser. Images in the SQL server are imported from MS Access 2002 I found the following code that mentions about removing the OLE Header for Northwind Database. I tried using the same logic to retrieve images from the database that I imported and got an error “Invalid parameter” when trying to run the program
4
6896
by: Rothariger | last post by:
Hello, i have a problem, i must to make a response.redirect, with a fixed header (authentication header) but i dont know how to do it... i make this, but im stuck here... Dim strURL As String = "http://localhost/webapplication1/webform1.aspx" Response.ClearHeaders() Response.ClearContent() Dim ReportWebRequest As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(strURL), System.net.HttpWebRequest)
7
2787
by: Nuno Magalhaes | last post by:
I've got a problem which relates to reading HTTP data. I've got the socket connected to a web site and then I send "GET / HTTP/1.1\n\n" and the page is received after a while but not all of the page. Should I implement a timer to read the web page? How do I know when the page is completed if sometimes socket.Available is 0? The procedure is as follows: -Socket socket=new...
3
1599
by: ross | last post by:
Hi Group, I am working on web service where I am trying to execute a remote URL from within a php file and would like to make some decisions depending on the output. I am using fopen to open the URL $handle=@fopen("www.mysite.com/api/command","r"); If the command is successful it returns an XML file with response headers. I have no problems reading the XML.
23
1995
by: shank | last post by:
I have the below code found on an ASP site. <% arrName = Split(Request("TextArea"),",") %> <% For i = LBound(arrName) To UBound(arrName) Response.Write "ID: " & arrName(i) & "<br>" Next %>
4
12152
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes without the user having to wait. I'm doing this (with fsockopen) by sending an http request to a page that does the time consuming stuff and then immediatly closing, without having read any of the response. This way, I don't have to wait for the...
4
14275
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
1
12616
by: mkwg | last post by:
Hi, I wonder if anyone can help with this question. I have a test servlet that simply echoes back XML text that is sent to it, with UTF-8 encoding. Here's the servlet code: public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); ServletInputStream sis =...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.