473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

HttpModule

PJ
Is it possible to capture a request as it hits the server and before the
post data has been completely sent to the web server?

Thanks~
Nov 17 '05 #1
3 2623
I've never done it, but you should be able to inspect the incoming stream vi
the request.filter. If you look in the HTTPModules section on www.asp.net
their is a long thread on uploading large files which covers this to some
degree.

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"PJ" <pj***@hotmail.com> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
Is it possible to capture a request as it hits the server and before the
post data has been completely sent to the web server?

Thanks~

Nov 17 '05 #2
PJ
I'm am looking for the posted contents as they come into the server, but
(IMPORTANTLY) before they have been completely sent. Specifically, I need
to let users upload ~ 1gb files so I need to grab the posted file bytes as
they are streaming into the server and save it to disk.

Can I do this by wiring an event to the BeginRequest in the Init event of a
module? Will the code below work? If so, how do I ensure that all of the
posted file bytes do not go into memory? Will the act of reading the bytes
ensure that the bytes do not go into memory as the request is sent on to the
page handler?

'sorry for the vb, forced to use this language
Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init
AddHandler app.BeginRequest, New EventHandler(AddressOf
Me.OnBeginRequest)
End Sub

Public Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim ctx As HttpContext = CType(sender, HttpApplication).Context
If ctx.Request.Files.Count > 0 Then
Dim fs As New FileStream(Path.Combine("c:\uploads",
Path.GetFileName(ctx.Request.Files(0).FileName)), FileMode.Create)
Dim br As New BinaryReader(ctx.Request.Files(0).InputStream)
Dim bw As New BinaryWriter(fs)
Dim size As Integer = 1024
Dim position As Integer
Do
If position + size > br.BaseStream.Length Then
size = Convert.ToInt32(br.BaseStream.Length) - position
End If
bw.Write(br.ReadBytes(size))
position += size
Loop Until position >= ctx.Request.Files(0).ContentLength
bw.Close()
br.Close()
fs.Close()
End If
End Sub

"Sreejumon[MVP]" <sr********@hotmail.com> wrote in message
news:03****************************@phx.gbl...
Hi,

Are you looking for the page header or request contents?

If youa re looking for request contents, then you can save
the request stream to file using SaveAs method of
HttpRequest class. If you need header specify the second
parameter of saveas fucntion.

Similay you can use the HTTPRespose obejcts method to
write the responze to file.
Let me know if you need further help.
regards
Sreejumon

-----Original Message-----
Is it possible to capture a request as it hits the server

and before the
post data has been completely sent to the web server?

Thanks~
.

Nov 17 '05 #3
Check out this article,
http://www.microsoft.com/india/msdn/...TPModulesinASP
..aspx

--
Saravana
Microsoft India Community Star,
MCAD,SE,SD,DBA.
"PJ" <pj***@hotmail.com> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
Is it possible to capture a request as it hits the server and before the
post data has been completely sent to the web server?

Thanks~

Nov 17 '05 #4

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

Similar topics

0
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our...
2
by: Rob Mayo | last post by:
What I'm trying to do is Create an ASP.Net app that has both Windows-authenticated users and Anonymous users. The idea is this: When authenticated users attempt to access the site, their...
1
by: Ryan Cromwell | last post by:
I have written an httpModule for use in our test environment. If a user goes to http://testserver/SomeApplication/MyPage.aspx it will resolve to the latest version of that application deployed:...
7
by: nail | last post by:
Folks, I develop a HttpModule and it works correct, but one problem is occurs. After I register the httpmodule in the web.config, my pages (not testing http://localhost/site but...
4
by: Danny W | last post by:
Hi There! Is it possible to use HttpModule to replace the built-in ASP.NET Session object? I want to write a HttpModule that will handle storing and retrieving of session values from an external...
2
by: Simon-Pierre Jarry | last post by:
Hi, I created a custom HttpModule for managing the security of my application. in "Init" sub, I regsiter the events doing that : Public Sub Init(ByVal context As System.Web.HttpApplication)...
2
by: walter | last post by:
Hi there, I know there is pool of HttpApplications, and for each request coming in, HttpRuntime will dedicate one from pool to serve the request. My questions are : 1. since HttpModule is plug...
1
by: Faraz | last post by:
Hi everyone, I am running into a slight problem. My understanding is that a custom HttpModule will run for every request made to the server, regardless of the extension. I do not experience this...
0
by: mattdev1000 | last post by:
Hello, I have an HttpModule that uses a lazy fetch to a secondary tier for calculating some values (the calculation is can be multisecond in the worse case). The HttpModule spins up a thread to...
3
by: Joseph Geretz | last post by:
I'm implementing a web application whose purpose in life is to act as a data conduit. Data is posted to my Web app in XML format, my application examines the data and forwards it onward by posting...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.