在asp.net中使用Gzip [帮助] [英] Gzip in asp.net[help]
本文介绍了在asp.net中使用Gzip [帮助]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我刚刚在gzip网站上发现错误了吗?帮帮我吧!
1.创建文件global.asax
<%@ 导入 命名空间 = System.IO %>
<%@ 导入 命名空间 = System.IO.Compression %>
< span class =code-leadattribute>< script runat = server < span class =code-attribute> >
protected void Application_PreRequestHandlerExecute( object sender,EventArgs e)
{
HttpCompress((HttpApplication)sender );
}
private void HttpCompress(HttpApplication app)
{
string acceptEncoding = app.Request.Headers [ 接受编码跨度>];
Stream prevUncompressedStream = app.Response.Filter;
if (!(app.Context.CurrentHandler 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]))
{
// < span class =code-comment> gzip
app.Response.Filter = new GZipStream(prevUncompressedStream,
CompressionMode.Compress );
app.Response.AppendHeader( Content-Encoding, gzip);
}
}
私有 静态 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临时压缩文件 >
< 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 >
这是错误:
服务器错误 ' /'应用程序。
编译错误
描述:编译服务此请求所需的资源时发生错误。请查看以下特定错误详细信息并相应地修改源代码。
编译器错误消息:BC30205:预期结束语句。
来源错误:
行 3 :
行 4 :< script runat = server >
行 5 : protected void Application_PreRequestHandlerExecute( object sender,EventArgs e)
Line 6 :{
行 7 :HttpCompress((HttpApplication)sender);
源文件:F:\ Webhn_Solution\Webhn \Webhn \ global.asax行: 5
我找不到预期陈述结束
解决方案
我看不到行:
<%@ 页面语言=C# %>那么也许是假设VB?
global.asax do没有<![CDATA [<%@ Page 语言 = C# %> ; ]]>
错误:
服务器错误' /'应用程序中的class =code-keyword>。
解析器错误
描述:解析服务此请求所需的资源时发生错误。请查看以下特定的解析错误详细信息并相应地修改源文件。
分析器错误消息:指令' page' 未知。
来源错误:
行 1 : <%@ Page 语言 = C# %>
第2行:<%@ 导入 命名空间 = System.IO %>
第3行:<%@ 导入 命名空间 = 系统。 IO.Compression %>
源文件: /global.asax行:1
版本信息:Microsoft .NET Framework版本:2.0.50727.5420; ASP.NET版本:2.0.50727.5420
您好,
我看到这一行:
< script runat = 服务器 >
您可以尝试将其更改为:
< script runat = server type = text / C# >
希望这会有所帮助。
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"
解决方案
I see no line:
<%@ Page Language="C#" %>So perhaps it is assuming VB?
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
Hi,
I see this line:
<script runat="server" >
You can try changing it into this:
<script runat="server" type="text/C#">
Hope this helps.
这篇关于在asp.net中使用Gzip [帮助]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文