Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HttpModule

Reply
Thread Tools

HttpModule

 
 
PJ
Guest
Posts: n/a
 
      07-17-2003
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~


 
Reply With Quote
 
 
 
 
John Timney \(Microsoft MVP\)
Guest
Posts: n/a
 
      07-17-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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~
>
>



 
Reply With Quote
 
 
 
 
PJ
Guest
Posts: n/a
 
      07-17-2003
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]" <(E-Mail Removed)> wrote in message
news:031b01c34c9f$7cfcd000$(E-Mail Removed)...
> 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~
> >
> >
> >.
> >



 
Reply With Quote
 
Saravana
Guest
Posts: n/a
 
      07-18-2003
Check out this article,
http://www.microsoft.com/india/msdn/...TPModulesinASP
..aspx

--
Saravana
Microsoft India Community Star,
MCAD,SE,SD,DBA.


"PJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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~
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HttpModule gets InProc Session_Start, not Session_End Steve Donnelly ASP .Net 0 08-30-2003 09:03 PM
HttpModule or Global.asax Juha Borenius ASP .Net 1 08-13-2003 02:05 PM
Can HttpHandler or HttpModule trap image requests? Peter Rilling ASP .Net 1 08-05-2003 11:07 AM
httpModule fails to load following upgrading to VS2003 Gary Varga ASP .Net 0 07-18-2003 10:20 AM
HttpModule for ASP and ASP.NET URL filtering Jon Sequeira ASP .Net 3 06-26-2003 03:36 PM



Advertisments