Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP ASP.NET
Hi everyone,i've just be error this here when gzip website?Help me!
1.create file global.asax
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.IO.Compression" %>
 
<script runat="server" >
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) 
    { 
        HttpCompress((HttpApplication)sender); 
    } 
    private void HttpCompress(HttpApplication app) 
    { 
        string acceptEncoding = app.Request.Headers["Accept-Encoding"]; 
        Stream prevUncompressedStream = app.Response.Filter; 
 

        if (!(app.Context.CurrentHandler is Page) || 
            app.Request["HTTP_X_MICROSOFTAJAX"] != null) 
            return; 
 

        if (string.IsNullOrEmpty(acceptEncoding)) 
            return; 
 

        acceptEncoding = acceptEncoding.ToLower(); 
 

        if ((acceptEncoding.Contains("deflate") || acceptEncoding == "*") 
            && CompressScript(Request.ServerVariables["SCRIPT_NAME"])) 
        { 
            // deflate 
            app.Response.Filter = new DeflateStream(prevUncompressedStream, 
                CompressionMode.Compress); 
            app.Response.AppendHeader("Content-Encoding", "deflate"); 
        } 
        else if (acceptEncoding.Contains("gzip") 
            && CompressScript(Request.ServerVariables["SCRIPT_NAME"])) 
        { 
            // gzip 
            app.Response.Filter = new GZipStream(prevUncompressedStream, 
                CompressionMode.Compress); 
            app.Response.AppendHeader("Content-Encoding", "gzip"); 
        } 
    } 
    private static bool CompressScript(string scriptName) 
    { 
        if (scriptName.ToLower().Contains(".axd")) return false; 
        return true; 
    } 
</script>
2.Web.config
<system.webServer>
    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
 
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
 
    <dynamicTypes>
 
    <add mimeType="text/*" enabled="true" />
 
    <add mimeType="message/*" enabled="true" />
 
    <add mimeType="application/x-javascript" enabled="true" />
 
    <add mimeType="*/*" enabled="false" />
 
    </dynamicTypes>
 
    <staticTypes>
 
    <add mimeType="text/*" enabled="true" />
 
    <add mimeType="message/*" enabled="true" />
 
    <add mimeType="application/x-javascript" enabled="true" />
 
    <add mimeType="*/*" enabled="false" />
 
    </staticTypes>
 
    </httpCompression>
 
    <urlCompression  doStaticCompression="true" doDynamicCompression="false" />
 
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00"/>
         
    </staticContent>
</system.webServer>  
This is error:
Server Error in '/' Application.
 
Compilation Error
 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
 
Compiler Error Message: BC30205: End of statement expected.
 
Source Error:
 

Line 3:  
Line 4:  <script runat="server" >
Line 5:  protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) 
Line 6:      { 
Line 7:          HttpCompress((HttpApplication)sender); 
 
Source File: F:\Webhn_Solution\Webhn\Webhn\global.asax    Line: 5  
i can't find "End of statement expected"
Posted 11-Jan-13 22:32pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I see no line:
<%@ Page Language="C#" %>
So perhaps it is assuming VB?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

global.asax do not have
<![CDATA[<%@ Page Language="C#" %>]]>
Error:
Server Error in '/' Application.
 
Parser Error
 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 
 
Parser Error Message: The directive 'page' is unknown.
 
Source Error: 
 

Line 1:  <%@ Page Language="C#" %>
Line 2:  <%@ Import Namespace="System.IO" %>
Line 3:  <%@ Import Namespace="System.IO.Compression" %>
 
Source File: /global.asax    Line: 1 
 
Version Information: Microsoft .NET Framework Version:2.0.50727.5420; ASP.NET Version:2.0.50727.5420
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
I see this line:
<script runat="server" >
You can try changing it into this:
<script runat="server" type="text/C#">
Hope this helps.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 318
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 PhilLenoir 60
4 nv3 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100