- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
有几个关于利用浏览器缓存的问题,但我没有发现任何关于如何在 ASP.NET 应用程序中执行此操作的有用信息。 Google 的 Pagespeed 告诉我们这是性能最大的问题。
到目前为止,我在我的 web.config 中做了这个:
<system.webServer>
<staticContent>
<!--<clientCache cacheControlMode="UseExpires"
httpExpires="Fri, 24 Jan 2014 03:14:07 GMT" /> -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.24:00:00" />
</staticContent>
</system.webServer>
cacheControlMaxAge
来设置从现在开始缓存静态内容的天数。这是行不通的。我的问题是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="exceptionManagement" type="Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManagerSectionHandler,Microsoft.ApplicationBlocks.ExceptionManagement" />
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E34" requirePermission="false" allowDefinition="Everywhere" />
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<exceptionManagement mode="off">
<publisher mode="off" assembly="Exception" type="blabla.ExceptionHandler.ExceptionDBPublisher" connString="server=188......;database=blabla;uid=blabla;pwd=blabla; " />
</exceptionManagement>
<location path="." inheritInChildApplications="false">
<system.web>
<httpHandlers>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e34" validate="false" />
<add verb="GET" path="Image.ashx" type="blabla.WebComponents.ImageHandler, blabla/>"
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" path="*.jpg" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.js" type="System.Web.StaticFileHandler" />
<add verb="*" path="*.gif" type="System.Web.StaticFileHandler" />
<add verb="GET" path="*.css" type="System.Web.StaticFileHandler" />
</httpHandlers>
<compilation defaultLanguage="c#" targetFramework="4.5.1" />
<trace enabled="false" requestLimit="100" pageOutput="true" traceMode="SortByTime" localOnly="true"/>
<authentication mode="Forms">
<forms loginUrl="~/user/login.aspx">
<credentials passwordFormat="Clear">
<user name="blabla" password="blabla" />
</credentials>
</forms>
</authentication>
<authorization>
<allow users="*" />
</authorization>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" uiCulture="en-GB" />
<xhtmlConformance mode="Transitional" />
<pages controlRenderingCompatibilityVersion="4.5" clientIDMode="AutoID">
<namespaces>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls>
</pages>
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
</system.web>
</location>
<appSettings>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="200000" />
</webServices>
</scripting>
</system.web.extensions>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v1.1.4122" />
<supportedRuntime version="v1.0.3705" />
</startup>
<system.webServer>
<rewrite>
<providers>
<provider name="ReplacingProvider" type="ReplacingProvider, ReplacingProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ab632b1f332b247">
<settings>
<add key="OldChar" value="_" />
<add key="NewChar" value="-" />
</settings>
</provider>
<provider name="FileMap" type="DbProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0525b0627da60a5e">
<settings>
<add key="ConnectionString" value="server=;database=blabla;uid=blabla;pwd=blabla;App=blabla"/>
<add key="StoredProcedure" value="Search.GetRewriteUrl"/>
<add key="CacheMinutesInterval" value="0"/>
</settings>
</provider>
</providers>
<rewriteMaps configSource="rewritemaps.config" />
<rules configSource="rewriterules.config" />
</rewrite>
<modules>
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3456AD264E35" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Web-JPG" path="*.jpg" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
<add name="Web-CSS" path="*.css" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
<add name="Web-GIF" path="*.gif" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
<add name="Web-JS" path="*.js" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto">
<remove statusCode="404" subStatusCode="-1"/>
<remove statusCode="500" subStatusCode="-1"/>
<error statusCode="404" path="error404.htm" responseMode="File"/>
<error statusCode="500" path="error.htm" responseMode="File"/>
</httpErrors>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soapBinding_AdriagateService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_ITravellerService" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="blabla" bindingConfiguration="soapBinding_blabla" contract="" Address="blabla" name="blabla" />
<endpoint address="blabla" binding="basicHttpBinding" bindingConfiguration="soapBinding_IImagesService"
contract="ImagesService.IImagesService" name="soapBinding_IImagesService"/>
<identity>
<servicePrincipalName value="blabla"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
</system.web>
<elmah>
<security allowRemoteAccess="false" />
</elmah>
<location path="elmah.axd" inheritInChildApplications="false">
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
</configuration>
cacheControlCustom="public"
:
<clientCache cacheControlCustom="public"
cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
最佳答案
大多数浏览器缓存问题可以通过查看响应头来解决(可以在谷歌浏览器开发者工具中完成)。
现在clientCache
您的 web.config
部分文件应该将您的输出缓存设置为最大年龄,如下图所示设置了 max-age
至 86400
这是 1 天(以秒为单位)。
这是此设置的 web.config 片段。
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
max-age
在
Cache-Control
上设置的属性标题。所以浏览器应该缓存内容。嗯,这基本上是正确的,但有些浏览器需要设置另一个标志。特别是
public
为缓存控制 header 设置的标志。这可以通过使用
cacheControlCustom
轻松添加。
web.config
中的属性.这是一个例子。
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
public, max-age=86400
.所以我们的浏览器拥有缓存资源所需的一切。现在检查谷歌浏览器的标题和网络选项卡将帮助我们。
(from cache)
走。
IHttpHandler
的通用处理程序(
Image.ashx
)内容类型为
image/jpg
.现在您可能期望默认行为是缓存此处理程序。但是 IIS 看到扩展名
.ashx
(正确地)作为动态脚本并且不受缓存的影响,而无需在代码本身中显式设置缓存 header 。
IHttpHandlers
实际上不应缓存,因为它们通常提供动态内容。现在,如果该内容不太可能更改,您可以直接在代码中设置缓存 header 。这是在
IHttpHandlers
中设置缓存头的示例使用
Response
语境。
context.Response.ContentType = "image/jpg";
context.Response.Cache.SetMaxAge(TimeSpan.FromDays(1));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetSlidingExpiration(true);
context.Response.TransmitFile(context.Server.MapPath("~/out.jpg"));
Cache
上设置一些属性的代码。属性(property)。为了获得所需的响应,我设置了属性。
context.Response.Cache.SetMaxAge(TimeSpan.FromDays(1));
告诉输出缓存设置 max-age=
Cache-Control
的一部分标题要1
future 的一天(86400 秒)。 context.Response.Cache.SetCacheability(HttpCacheability.Public);
告诉输出缓存设置 Cache-Control
标题到 public
.这非常重要,因为它告诉浏览器缓存对象。 context.Response.Cache.SetSlidingExpiration(true);
告诉输出缓存确保它正在设置 max-age=
Cache-Control
的一部分标题正确。如果不设置滑动过期时间,IIS 输出缓存将忽略最大年龄 header 。把这些放在一起给了我这个结果。 .ashx
文件,因为它们通常提供动态内容。但是,如果该动态内容在给定时间内不太可能发生变化,您可以使用上述方法来交付您的
.ashx
文件。
An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL. If the resource content at that URL ever changes, a new and different
ETag
is assigned.
If-None-Match
带有
ETag
的标题从上次回复来看。我们可以修改我们的处理程序来检测
If-None-Match
标题并将其与我们自己生成的
Etag
进行比较.现在没有精确的科学来生成
ETags
但一个好的经验法则是提供一个标识符,它很可能只定义一个实体。在这种情况下,我喜欢使用连接在一起的两个字符串,例如。
System.IO.FileInfo file = new System.IO.FileInfo(context.Server.MapPath("~/saveNew.png"));
string eTag = file.Name.GetHashCode().ToString() + file.LastWriteTimeUtc.Ticks.GetHashCode().ToString();
GetHashCode()
方法(在所有对象上)获取对象的整数哈希码。在示例中,我连接了文件名的哈希值,然后是上次写入日期。最后写入日期的原因是如果文件被更改,哈希码也会更改,从而使指纹不同。
306894467-210133036
的哈希码。 .
System.IO.FileInfo file = new System.IO.FileInfo(context.Server.MapPath("~/out.png"));
string eTag = file.Name.GetHashCode().ToString() + file.LastWriteTimeUtc.Ticks.GetHashCode().ToString();
var browserETag = context.Request.Headers["If-None-Match"];
context.Response.ClearHeaders();
if(browserETag == eTag)
{
context.Response.Status = "304 Not Modified";
context.Response.End();
return;
}
context.Response.ContentType = "image/jpg";
context.Response.Cache.SetMaxAge(TimeSpan.FromDays(1));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetSlidingExpiration(true);
context.Response.Cache.SetETag(eTag);
context.Response.TransmitFile(file.FullName);
Etag
散列,检查传入
If-None-Match
标题。如果 etag 哈希值和 header 相等,那么我们通过返回状态码
304 Not Modified
告诉浏览器内容没有改变。 .
ETag
通过调用标题:
context.Response.Cache.SetETag(eTag);
ETag
正在作为 header 传递,浏览器正在发送请求 header
If-None-Match
所以我们的处理程序可以相应地响应缓存文件的更改。
关于c# - 利用 IIS 中的浏览器缓存(谷歌页面速度问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21074198/
当我查看 IIS 日志文件时,我可以在一天中的不同时间看到标题行被写入日志文件。我唯一一次看到这种情况发生是在 IIS 重置时;或启动。 例如下面的标题行; #Software: Microsoft
有谁知道为什么以下 web.conig 更改不起作用: 在我添加 javascript 文件后仍然没有被压缩(gzip)。我折腾了几天,因为一开始我真的不知道问题是
目前,我们所有的网络应用程序都将其应用程序池标识设置为 ApplicationPoolIdentity。现在,当一个应用程序需要访问某些服务器上的某些资源时,比如添加/读取某些文件,该应用程序会在代码
在 IIS(特别是 6.0)中,在“主目录”选项卡下,如果我更改本地路径,是否会导致 IIS 重新启动或应用程序池回收? 相关的,是否有概述 IIS 元数据库的哪些更改将触发重新启动或应用程序池回收的
只要更改了任何 web.config 文件,AFAIK IIS 就会重新启动。 我创建了自己的配置文件(my.config,层次结构略有不同)。是否有可能让 IIS 自动(自动神奇地 :))重新启动,
你好, 我正在寻找 IIS 日志中列出的浏览器条目列表,以帮助识别访问我们网站的不同版本的浏览器。也许没有一个列表,而是一个应该用来识别不同浏览器及其版本的算法。 请注意,我不是在寻找日志分析器,而是
我想知道上次重新启动 iis 是什么时候。 IIS 是否保留了此日志,我在哪里可以找到此日志? 谢谢 最佳答案 打开事件查看器,导航到“Windows 日志”->“系统” 在右侧的“操作” Pane
在全新安装的带有 IIS 7 的 Windows Server 2008 R2 上,它会在 C:\inetpub\wwwroot 中创建一个默认网站。 .我确信对于存储网站文件的好位置有很多主观意见,
我已按照 this question 中的说明在 IIS 中实现动态内容压缩。 . 当我发送请求时,我看不到响应被 gzip 压缩的任何证据: IIS版本为7.5 有什么明显的我应该检查以解决此问题吗
这是场景: 服务器 A 托管“主”应用程序 (www.example.com) 服务器 B 托管支持应用程序 (b.example.com) 它们通过 192.* 地址在内部相互连接,并且都可以通过
是否有任何替代 IIS 管理 UI 可用于从程序重置 IIS?.. 现在我们已经创建了一个批处理文件,如果 iis 重置并每小时安排一次...... 我只是想要一些东西,这样我们就不能重置 iis..
我的 Windows Server 在 IIS 7.5 上运行 Web 应用程序。 我想知道为什么 IIS 应用程序池使用大量内存。 请参阅我从服务器捕获的屏幕截图。 在名为 TEST 2.0(.NE
我在 IIS 7.5 上运行的 ASP Classic 站点上收到服务器错误。 我将“向浏览器发送错误”设置为 True ,但是我仍然收到以下错误屏幕: 最佳答案 IIS 正在劫持您的经典 ASP 应
我正在尝试通过IIS上的反向代理连接到websockets服务器(websockify)。 IIS和Websockets服务器位于同一台物理服务器上(Windows Server 2012 R2,II
我需要让我的开发机器从本地机器商店读取证书 为此,我需要运行winhttpcertcfg.exe并指定我要提升的帐户 该帐户用于IIS表示什么? (对于IIS,它将是IWAM_MachineName)
我正在阅读特定命令(SET-WEBCONFIGURATIONPROPERTY),但出现"is not recognized as a cmdlet"错误。给我的建议是,即使我使用的是SharePoin
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我已经从官方镜像(https://hub.docker.com/r/microsoft/iis/)运行了IIS 在Windows Server 2016上 有什么方法可以从IIS管理器连接到该IIS,
你好, 如果 iis 未运行,我想编写一个状态为的代码。 最佳答案 从命令行启动 IIS: iisreset /start 从命令行停止 IIS: iisreset /stop 重新启动(停止和启动)
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我是一名优秀的程序员,十分优秀!