473,221 Members | 1,749 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,221 software developers and data experts.

Response Filter losing data when response is buffered

I have a response filter which injects "standard" html into my pages. The
filter works fine when the initial stream is small enough not to
buffer...or....if I have a large unbuffered stream (i.e. I set buffer=false
on a large page). Now the problem: If I turn on buffering on a large
page, the page output (to the browser) is correct a few times (sometines
just once, sometime 2-3 times...on the same page) then I seem to either
lose data or get corrputed data (I'm not sure which) in the middle of the
stream. The problem seems to persist until the page in my local web servers
cache (?) is cleared out i.e. I browser to some other pages then browse
back to the problem page.

I've compared the size of the buffer at the start and end of my filter's
write sub on the calls when it works when it does not and the buffers are
the same size which make it look like I'm not droping characters. The large
page has embedded encrypted client script from a third party control and
I've wondered if that script could be getting corrupted from the
UTF8Encoding.UTF8.GetString and/or the later UTF8Encoding.UTF8.GetBytes in
the write sub.

Anyone have thoughts or suggestions as to what to look for?

Thanks

Brad
Nov 18 '05 #1
3 2412
Hi Brad,

Thanks for posting in the community!
From your description, you used a certain Custom Response Filter to add
some certain html code into the response stream. However, you found the
page which has applied the Filter will output incompleted or corrupted
response data when the page's response content is large enough to buffer
and the Response's Buffer is set as true, yes?
If there is anything I misunderstood, please feel free to let me know.

I'm not sure the detailed operations in your filter, can you repro this
problem via certain code logic and steps? Or just a certain simple sample
Filter class to repro this problem?
Have you tried applied another certain filter class on the page's response
to see whether this problem remains?
If so , I think I can do some further tests on my side on this issue.
Please check the above items and let me know if you have any findings.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #2
Steven -
I've resolved the problem. Here's what I found and how I resolved it:

First, I simplified the filter's Write sub to the following and still had
the problem.
=============================
Friend Class ResponseFilter
Inherits Stream
Private responseStream As Stream

Public Overrides Sub Write(ByVal buffer() As Byte, ByVal offset As
Integer, ByVal count As Integer)
Dim sBuffer As String =
System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count)

' Here is where code could be placed to manipulate content of
sBuffer before writing to stream

buffer = System.Text.UTF8Encoding.UTF8.GetBytes(sBuffer)
responseStream.Write(buffer, offset, buffer.Length)
End Sub

=============================
I resolved the problem, by appending the writes buffer content into a
stringbuilder. When I detect </html> in the buffer I know I've received the
last buffer (last call to write). I make my changes to the contents of the
stringbuilder and write the entire content to the stream.

Friend Class ResponseFilter
Inherits Stream
Private responseStream As Stream
Private html As StringBuilder = New StringBuilder
...
Public Overrides Sub Write(ByVal buffer() As Byte, ByVal offset As
Integer, ByVal count As Integer)
Dim sBuffer As String =
System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count)
html.Append(sBuffer)

Dim oEndFile As Regex = New Regex("</html>",
RegexOptions.IgnoreCase)

If (oEndFile.IsMatch(sBuffer)) Then
Dim tempResponse As String = html.ToString()
buffer = System.Text.UTF8Encoding.UTF8.GetBytes(tempRespons e)
responseStream.Write(buffer, 0, buffer.Length)
End If
End Sub
=============================

If you see anything bad still or have suggestions please let me know.

Thanks

Brad

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:tD**************@cpmsftngxa07.phx.gbl...
Hi Brad,

Thanks for posting in the community!
From your description, you used a certain Custom Response Filter to add
some certain html code into the response stream. However, you found the
page which has applied the Filter will output incompleted or corrupted
response data when the page's response content is large enough to buffer
and the Response's Buffer is set as true, yes?
If there is anything I misunderstood, please feel free to let me know.

I'm not sure the detailed operations in your filter, can you repro this
problem via certain code logic and steps? Or just a certain simple sample
Filter class to repro this problem?
Have you tried applied another certain filter class on the page's response
to see whether this problem remains?
If so , I think I can do some further tests on my side on this issue.
Please check the above items and let me know if you have any findings.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #3
Hi Brad,
Thanks for your followup. I'm glad that you've figured out this problem.
The StringBuilder will provide high performance when doing string
manipulation. Here is the description in MSDN:
----------------------------------------------------------
The String object is immutable. Every time you use one of the methods in
the System.String class, you create a new string object in memory, which
requires a new allocation of space for that new object. In situations where
you need to perform repeated modifications to a string, the overhead
associated with creating a new String object can be costly. The
System.Text.StringBuilder class can be used when you want to modify a
string without creating a new object. For example, using the StringBuilder
class can boost performance when concatenating many strings together in a
loop.
----------------------------------------------------------
Also, here are some tech articles discussing on this:
#HOW TO: Improve String Concatenation Performance in Visual Basic .NET
http://support.microsoft.com/?id=306821

#Efficient String Manipulations with StringBuilder
http://www.ondotnet.com/pub/a/dotnet...15/string.html
Maybe the large page with buffer turn on cause string to realloc again and
again cause the unexpected problem. But I'm still so surprised at this
result. Any way, thanks again for providing us your experience.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4

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

Similar topics

7
by: Larry Woods | last post by:
Could you give me an example of streaming a page to the client? Thanks. Larry Woods
0
by: Copa | last post by:
Hello, I am testing buffering an asp page and Flushing information out to the browser, hence i wrote the code in an asp page that follows this Message Post. The loops are suppose to simulate...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
5
by: Paul de Goede | last post by:
I set the Response.Filter in my aspnet application but I have noticed that if you do a Server.Transfer that the filter doesn't get called. And in actual fact the response is mostly empty. It seems...
7
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge...
10
by: GreggTB | last post by:
I've got an page (LOGIN.ASPX) that receives the user's login information. During the page load, it checks the credentials against a database and, if validation is successful, creates an instance of...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
1
by: ocbka1 | last post by:
i'm using creating a webpage on the fly that i save as an xls file to be attached to an email and sent dynamically. i've got a custom response filter class to write it out. the problems start...
7
by: eventuranza | last post by:
For my application, there users can upload and download files to the a webserver. Straightforward enough. However, when they upload a PDF file then try to download it, the file seems to be...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.