2

問題が発生しました。web.configファイルのコードでaspxのHTTPHandlerとして使用しているタイプを作成しました。

<add path="*.aspx" verb="*" type="myHandler"></add>

csページは

public class myHandler :  IHttpHandler
{
    public void ProcessRequest(System.Web.HttpContext context) 
    {
        // check if client browser can accept gzip encoding
        string AcceptEncoding = context.Request.Headers["Accept-Encoding"];
        if (!string.IsNullOrEmpty(AcceptEncoding) && AcceptEncoding.Contains("gzip"))
        {
            // if yes, apply it
            context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
            context.Response.AddHeader("Content-Encoding", "gzip");
        }
        // don't do anything else, just let the default page handling work
    }

    public bool IsReusable
    {
        get { return false; }
    }

}

ご覧のとおり、クライアントがgzipエンコーディングを受け入れるかどうかを確認しています。受け入れている場合は、それを追加して、デフォルトのプロセスに処理させます... しかし、私が得ている応答はです。

XML Parsing Error: no element found
Location: http://localhost:49903/Masters/Default.aspx
Line Number 1, Column 1:
^

すべてのページがこのエラーを返していますか?ハンドラーでリクエストを処理した後、他のすべてまたは関連するものをなんとかしてクリアしていると思います。

Firebugは次のことを示しています。

Response Headers

Cache-Control   private
Connection  Close
Content-Encoding    gzip
Content-Length  0
Date    Sat, 06 Oct 2012 13:14:50 GMT
Server  ASP.NET Development Server/10.0.0.0
X-AspNet-Version    4.0.30319


Request Headers

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Cookie  ASP.NET_SessionId=1wfoaqta3mosntii1c3ual1i; .ASPXAUTH=D41BBDC2CCF15048BB5A345EBBFBC63EAE35FD37E2F1F170C1D68495477889A989353D4EB30F2B9A723F83C21293A47478B654A1BD2453BCF032DC539427EA0E519D2FEE70DB7660F00AA90E159633C4
Host    localhost:49903
Referer http://localhost:49903/Masters/Default.aspx
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1


Request Headers From Upload Stream

Content-Length  8241
Content-Type    multipart/form-data; boundary=---------------------------2995119424827

だから、私が推測していることから、私が自分のやり方でページを処理した後、私がのようなことをすることができる方法があることを知りたいですbase.ProcessRequest()。私はインターフェイスを実装していて、クラスから派生していないため、それが不可能であることを知っていますが、知りたいのですが、私の作業が終わった後、asp.netエンジンにページを処理させるにはどうすればよいですか?

注意:この質問はgzibエンコーディングの実装に関するものではありません。これは、Web構成、各ページ、IISで設定したり、ユーティリティクラスで静的関数を作成して呼び出したりすることができます。しかし、繰り返しになりますが、このgzipエンコーディングを実装するために別の方法を使用できると答えないでください。が懸念しているのは、asp.netにデフォルトの処理(またはそれが意味するもの)を実行させる方法です。カスタム処理は完了しましたか?

4

1 に答える 1

1

あなたは間違った道をたどります。使用しようとしているハンドラーは、異なる拡張子で終わるある種のファイルを処理するためのまったく異なる方法を作成するためのものです。.aspx次に、そのページを処理し、asp.netがページを処理することをまったく許可しません。

あなたがすべきことはhttpModule、例えば、次のようなクラスを作成することです。

public class gZipModule : IHttpModule
{
    void IHttpModule.Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void IHttpModule.Dispose()
    {
    }

    private void context_BeginRequest(object sender, EventArgs e)
    {
        // gzip here
    }
}

およびWeb構成:

<httpModules>
   <add type="gZipModule"  name="gZipModule" />
</httpModules>

またはさらに簡単に、gZipでglobal.asax作成しますApplication_BeginRequest

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    // check if the file is .aspx, then make gzip
    string cTheFile = HttpContext.Current.Request.Path;
    string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);

    if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
    {   
        // now make gZip
    }
}
于 2012-10-06T15:03:49.207 に答える