473,386 Members | 1,679 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,386 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 2624
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.