.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Invalid use of Response.Filter exception, possible ASP.NET bug

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

We have an HTTP module that compresses the Response Output (gzip) as followed:

  public class PageModule : IHttpModule
       void app_AcquireRequestState(object sender, EventArgs e)
HttpContext.Current.Response.Filter = new GZipStream(HttpContext.Current.Response.Filter, CompressionMode.Compress);


Now, this code works fine for all the pages EXCEPT a asynchronous IHTTPHandler that serves files. The code for that is:

  public class DownloadHandler : IHttpAsyncHandler
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
    AsyncProcessorDelegate asyncDelegate = new AsyncProcessorDelegate(ProcessRequest);
            return asyncDelegate.BeginInvoke(context, cb, extraData);

  public void ProcessRequest(HttpContext context)


When the asynchronous file transfer is done, the .NET engine throws an exception "Invalid use of Response.Filter". Below is the stack:
at System.Web.HttpResponseStreamFilterSink.VerifyState()
at System.Web.HttpResponseStreamFilterSink.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Compression.DeflateStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Compression.GZi

View Complete Post

More Related Resource Links

How to CATCH "Invalid postback or callback argument" exception?



How can I catch this exception? I do not want it to stop my page execution. Can/Should I do that?

Server Error in '/' Application.
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally

An exception occurred during the operation, making the result invalid

Hi I am using WCF services with WPF, both are .net 4 versions. I am calling asynchronously, During method calls, sometimes I get the following error Void RaiseExceptionIfNecessary()---An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() I tried alot to find the reason , but unable to find as it is unpredictable and inconsistent. Seeking for kind help from WCF guruzzz... Regards Zee

Invalid DateTime Exception

Hi, I have a problem in my application using by 1.5 million users. During peak hours of usage, one or twice in a day, application started throughing exceptions, DateTime is invalid  on all pages where datetime conversion is applied (value mostly comes from database sever). And the problem only resolves if we reset the application. This is very annoying and causing frustation in users. An urgent reply needed. Thanks in advance Farrukh 

How to remove conflict between Sharepoint 2010 Post Cache Substitution and Response.Filter

Under SharePoint 2007 (Win Server 2008, SQL 2008) we made use of Response.Filter to meet certain requirements for accessibility to remove certain markup or add to markup that was missing attributes, etc. When we upgraded to SharePoint 2010 we get the following error message from the pages, unless we remove the use of Response.Filter: "Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers.  Either a native module in the pipeline has modified an HTTP_DATA_CHUNK structure associated with a managed post cache substitution callback, or a managed filter has modified the response." I have found several posts including this article http://support.microsoft.com/kb/2014472 that explains that it is definately a problem, but no one has an alternative solution to using the Response.Filter, and the article doesn't say how to disable the use of Post Cache Substitution. So, my question is how do I turn off the use of Post Cache Substitution in SharePoint 2010, or how can I alter the final markup of the page "After" the substitution happens?  Or, if it is a control or three that are using Post Cache Substitution, which one(s) so that I can remove them.

Invalid cast exception...


I thought I had mastered all this.. I'm testing for dbnull. This exception isn't occuring in my code. It's in some other code. What does this "strong typing exception" mean?

Imports DataSet2TableAdapters
Partial Class admin_fixdb
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim I As Integer
        Dim S1 As String
        Dim S2 As String
        Dim S3 As String
        Dim J As Integer
        Dim k As Integer
        Dim l As Integer
        Dim s4 As String
        Dim s5 As String
        Dim s6 As String

        Dim tbllinkadapter As New tblLinkTableAdapter
        Dim tbllink As DataSet2.tblLinkDataTable
        tbllink = tbllinkadapter.GetData
        For Each tbllinkrow As DataSet2.tblLinkRow In tbllink
            If Not IsDBNull(tbllinkrow.SenderLinkOn.ToString) Then
                I = tbllinkrow.SenderLinkOn.IndexOf(".")
                If tbllinkrow.SenderLinkOn.Substring(I - 1, 1) = "_" Then
                    J = Len(tbllinkrow.SenderLinkOn)
                    S1 = tbllinkrow.SenderLinkOn.Substring(0, I - 1)
                    S2 = tbllinkrow.SenderLinkOn.Substring(I, (J - I))
                    S3 = S1 + S2
                    Response.Write("Senderlinkon: " & S3)

Invalid Handle exception when browsing a site on the web front end


We are building a 3-tiered SharePoint 2010 farm that consists of 1 web front end (WFE), 1 app/CA server, and 1 database server.  All servers are running Windows 2008 service pack 1.  We can browse the Central admin site without any issue, but when we attempt to access sites on the WFE we get the following exception:


Server Error in '/' Application.

The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack t




I am trying to modify the output html of a aspx page, on output. I am using an http model to do this.

however i am getting a error whan i try to read the stream, "the stream is not readable"

any ideas thanks

public class MobiMod : IHttpModule
    private System.Web.HttpApplication app;
    public MobiMod()
        // TODO: Add constructor logic here

    public void Dispose()


    public void Init(HttpApplication application)
        application.EndRequest += new System.EventHandler(EndRequest);

        app = application;


    public void EndRequest(Object sender, EventArgs e)
        HtmlFilter OutputFilter = new HtmlFilter();


Linq2SharePoint Invalid Cast Exception


I'm trying to use Linq2SharePoint to get a count if items in a document library using the following code:


var context = new MyDataContext(webUrl);

var count = (from item in context.MyDocumentLibrary.ScopeToFolder("/", true).OfType<NewBusinessApplication>()
       where item.NewBusinessStatus = "Validation"
       select item).Count()

This should return a count of all NewBusinessApplication documents in all folders with the NewBusinessStatus of Validation.

If a run this on a document library with a mixture of document types it behaves as expected.  However, if a workflow has run on one of the NewBusinessApplication documents I get and InvalidCastException.

It appears from the stack trace that the error is when it's mapping the SPListItem to the concrete type generated by SPMetal but I can't find the specific column that's causing the issue.

Any suggestions or known issues I should look o

SOAP response XML Exception



   I am using C#.Net 3.5 to consume a Web Service (http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_seq.wsdl) which has been working for me for years. About a week ago I started getting XML errors (see below for exception details) from the XML deserializer before I can even see the response from the Web Service. I used "snoop" (http://msdn2.microsoft.com/en-us/library/ms176041.aspx) to look at the XML being returned and it looks fine to me. I can even load that XML using XmlDocument.Load and I get no errors that way. Could .Net have different validation for SOAP than other xml documents? I am guessing that there is something bad happening before "snoop" can get it hands on the XML. Any idea what or what to do about

Invalid Exception in Datagrid


There is a code as following:

switch (((System.Web.UI.WebControls.LinkButton)e.CommandSource).CommandName)
                    case "statusActive":
                    case "statusClosed":

I am getting the following error:


Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

Using jQuery to Filter Table Rows

The project is using the .net GridView control, so I had limited control over the output HTML code. Still, I think this code can work for most tables. One thing to notice: you should use the class "filterable" on your table or on one of its parents for the code to work.
First, we need a text box:

GridView Multiple Filter AJAX Control

This AJAX control enables the user to filter data within any column inside a GridView. The user can add multiple filters and can delete existing ones too.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

Response.BinaryWrite help needed


Hi all

Im new to .NET and stuck now, so i hope anyone can help my with my problem.

I have a MS SQL database where i have stored some documents as Binary data. I cant figure out how to retrieve them and show/download them in my browser.

I found some guides online and have try to put something together.


private void Write()
 int id = 0;
 string strID = Request.QueryString["id"];
 int.TryParse(strID, out id);

 var db = new ModelDataContext();
 var doc = db.DocumentDatas.Where(x => x.ID == id).FirstOrDefault();

 byte[] byteArray = File.ReadAllBytes(doc);


How do i fill the byteArray with the data?

Thanks in advance :)


Response.Redirect slow


I'm in the middle of migrating servers and on the new server Response.Redirect is extremely slow. It takes around 20 seconds for the browser to get the redirect. This is something that was quick on the existing server. It's an ASP.NET 2.0 application, both servers are running IIS6.

Additionally, if I "manually" do the redirect, it's fast. For example:

Existing way:


takes around 20 seconds on the new server

New way:

Response.Status = "302 Moved Temporarily";
Response.AddHeader("Location", url);

is fast on the new server.

Any ideas why Response.Redirect would be so slow on the new server?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend