2012-03-08 14 views
0

私のアプリケーションでは、jsonオブジェクトの配列を取得するjqueryポストを行います。 iis7.5とjsonの両方で行う必要がある設定は何ですか?jqueryポストを持つasp.netのGzip圧縮設定

私はjqueryのポストでHttpModuleを

private void Compress(object sender, EventArgs e) 
     { 
      HttpApplication app = (HttpApplication)sender; 
      HttpRequest request = app.Request; 
      HttpResponse response = app.Response; 

      //Ajax Web Service request is always starts with application/json 
      if (request.ContentType.ToLower(CultureInfo.InvariantCulture).StartsWith("application/json")) 
      { 
       //User may be using an older version of IE which does not support compression, so skip those 
       if (!((request.Browser.IsBrowser("IE")) && (request.Browser.MajorVersion <= 6))) 
       { 
        string acceptEncoding = request.Headers["Accept-Encoding"]; 

        if (!string.IsNullOrEmpty(acceptEncoding)) 
        { 
         acceptEncoding = acceptEncoding.ToLower(CultureInfo.InvariantCulture); 

         if (acceptEncoding.Contains("gzip")) 
         { 
          response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); 
          response.AddHeader("Content-encoding", "gzip"); 
         } 
         else if (acceptEncoding.Contains("deflate")) 
         { 
          response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress); 
          response.AddHeader("Content-encoding", "deflate"); 
         } 
        } 
       } 
      } 
     } 

カスタムを作った、私は

$.ajax({ 
    type: "POST", //GET or POST or PUT or DELETE verb 
    url: newGrid.Serviceurl, // Location of the service 
    data: JSON.stringify(newGrid), //Data sent to server 
    contentType: newGrid.contenttype, // content type sent to server 
    dataType: "json", //Expected data format from server 
    processdata: true, //True or False 
    beforeSend: function (request) { 
     request.setRequestHeader("Accept-Encoding", "gzip"); 
    }, 
    success: function (result) { // get an array of json objects 
     alert('done'); 
    } 
}); 

web.configファイルの変更を追加 -

<httpModules> 
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    <add name="GzipCompression" type="GzipCompression"/> 
</httpModules> 

を私は必要とする他の設定の変更があります作る。

+0

ブラウザに「Accept-Encoding」と尋ねた瞬間から、IEのチェックは不要です。 – Aristos

答えて

0

エラーはweb.configエントリに原因があります。 IIS7.5で使用されます。

関連する問題