Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,i've just be error this here when gzip website?Help me!
1.create file global.asax
C#
<%@ 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
C#
<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:
C#
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

I see no line:
CSS
<%@ Page Language="C#" %>
So perhaps it is assuming VB?
 
Share this answer
 
global.asax do not have
C#
<![CDATA[<%@ Page Language="C#" %>]]>

Error:
C#
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
 
Share this answer
 
Hi,

I see this line:
ASP
<script runat="server" >

You can try changing it into this:
ASP
<script runat="server" type="text/C#">

Hope this helps.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900