Asp.net core 學習筆記 ( IIS, static file 效能優化 )

refer : 

https://weblog.west-wind.com/posts/2017/Apr/27/IIS-and-ASPNET-Core-Rewrite-Rules-for-AspNetCoreModule

https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?tabs=aspnetcore2x

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files

https://andrewlock.net/html-minification-using-webmarkupmin-in-asp-net-core/

https://github.com/Taritsyn/WebMarkupMin

 

core host in IIS 會攔截所有的請求, 包括靜態文件

可是 IIS 處理靜態文件壓縮等等還是不錯的 

那我們可以在 webconfig 裡去設定一下 

<configuration>
  <system.webServer>
    <rewrite>
        <rules>
            <rule name="wwwroot-static">
                <match url="([\S]+[.](html|htm|svg|js|css|png|gif|jpg|jpeg|json|mp3|mp4|woff|woff2))" />
                <action type="Rewrite" url="wwwroot/{R:1}" />
            </rule>
        </rules>
    </rewrite>
    <handlers>          
        <add name="StaticFileModuleSvg" path="*.svg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleJs" path="*.js" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleCss" path="*.css" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleJpeg" path="*.jpeg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleJpg" path="*.jpg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModulePng" path="*.png" verb ="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleGif" path="*.gif" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleJson" path="*.json" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleMp4" path="*.mp4" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleMp3" path="*.mp3" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleWoff" path="*.woff" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
 <add name="StaticFileModuleWoff2" path="*.woff2" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />           
    </handlers>
    <aspNetCore processPath=".\Project.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <remove fileExtension=".mp4" />
      <mimeMap fileExtension=".mp4" mimeType="audio/mp4" />
      <remove fileExtension=".ogg" />
      <mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
      <!--local iis no allow below-->
      <remove fileExtension=".less"/>
      <mimeMap fileExtension=".less" mimeType="text/css" />
      <remove fileExtension=".woff2"/>
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      <clientCache cacheControlMode="UseExpires" httpExpires="Tue, 12 Jan 2027 03:14:07 GMT" />
    </staticContent>
    <defaultDocument>
      <files>
        <clear />
        <add value="index.aspx" />
        <add value="Default.aspx" />
        <add value="index.html" />
        <add value="Default.html" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

做一個 rewrite 還有 handlers 就可以了. 

如果要處理 html minify 可以使用這個 plugin WebMarkupMin

 

關鍵詞:add file name modules path verb resourcetype staticfilemodule fileextension read

相關推薦:

The HTTP OPTIONS request on the Azure Web sites fails due to CORS

core 部署

python釋出IIS

Azure Web應用中設定靜態虛擬目錄的方法(比如部署Django需要用到)

2、Qt Project之滑鼠事件監控

zabbix自定義模板——監控TCP連線狀態

許可權管理demo-pom.xml

asp.net處理事件

JS表格分頁(封裝版)

ZABBIX 3.4 監控Nginx 狀態(七)