2012-02-24 5 views
1

私はこのようなglobal.ascxでApplication_PreRequestHandlerExecuteと呼ばれるメソッドを追加しました:コードレベルでasp.netページを圧縮する方法は?

void Application_PreRequestHandlerExecute(object sender, EventArgs e) 
{ 

    string cTheFile = HttpContext.Current.Request.Path; 
    string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile); 

    if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase)) 
    { 
     HttpApplication httpApp = (HttpApplication)sender; 

     string acceptEncoding = httpApp.Request.Headers["Accept-Encoding"]; 
     if (string.IsNullOrEmpty(acceptEncoding)) 
     { 
      return; 
     } 
     acceptEncoding = acceptEncoding.ToLower(); 

     System.IO.Stream requestStream = httpApp.Response.Filter; 

     if (acceptEncoding.Contains("gzip")) 
     { 
      httpApp.Response.Filter = new System.IO.Compression.GZipStream(requestStream, 
       System.IO.Compression.CompressionMode.Compress); 
      httpApp.Response.AppendHeader("Content-Encoding", "gzip"); 
     } 
     else if (acceptEncoding.Contains("deflate")) 
     { 
      httpApp.Response.Filter = new System.IO.Compression.DeflateStream(requestStream, 
       System.IO.Compression.CompressionMode.Compress); 
      httpApp.Response.AppendHeader("Content-Encoding", "deflate"); 
     } 
    } 

} 

通常のページを閲覧するとき、それが働いています。

が、ページが含まれている場合はUPDATE-PANELエラーが発生します。 PageRequestParserExceptionが発生します。 アップデートパネル非同期ポストバック時、このエラーが発生します。

+1

あなたはplsは要求 –

+0

@SanjayGoswami PageRequestParserException –

+0

@SanjayGoswami PageRequestParserException更新パネルはポストバック時にそれが起こるのエラーtelllことができますか? –

答えて

0

私は自分のページにfalseに設定されEnableEventValidationで「固定」とページのコンストラクタに圧縮ロジックを移動します。明らかに、これは良い解決策ではありません(近い検証)。 誰かが良い解決を知っているなら、plsは私に知らせる。

とすべてが、正常に動作します が、バージョンが2.0の場合、プロジェクトのフレームワークのバージョン場合は3.5であることがわかりました。このエラーが発生します。

関連する問題