1. 程式人生 > >Windows Server 2008 IIS上傳檔案大小設定

Windows Server 2008 IIS上傳檔案大小設定

Windows server 2008中的IIS7.0的asp.net寫的上傳,上傳大檔案有幾個地方需要設定

1.系統本身

修改C:/Windows/System32/inetsrv/config/schema/IIS_schema.xml檔案(修改該檔案需要獲得這個檔案的控制權,需要先獲得這個檔案的所有者,所有者是TrustedInstaller,改成administrator後,把屬性只讀改掉,就可以改了。但是再把所有者改回TrustedInstaller就改不回去了,不知道為什麼),找到maxAllowedContentLength, 其預設值為30000000,即30M,加一個0 就變成了 300MB 了就應該夠用了,如果不起作用,則需要重啟 IIS 7即可:

       <element name="requestLimits">
           <attribute name="maxAllowedContentLength" type="uint" defaultValue="30000000" />
           <attribute name="maxUrl" type="uint" defaultValue="4096" />
          <attribute name="maxQueryString" type="uint" defaultValue="2048" />
          <element name="headerLimits">
          <collection addElement="add" clearElement="clear" removeElement="remove" >
             <attribute name="header" type="string" required="true" isUniqueKey="true" validationType="nonEmptyString" />
             <attribute name="sizeLimit" type="uint" required="true" />
          </collection>
      </element>

2.IIS7.0本身

開啟IIS管理器–雙擊“IIS”中的“ASP”– 開啟“配置 ASP 應該程式的屬性”–展開“限制屬性”;修改“最大請求實體主體限制”的值,預設值為200000(即不到200KB);把它修改為你想修改的大小

3.asp.net本身web.config

單位是KB,1024KB=1MB.

  <system.web>   

    <!-- 設定可上傳的最大檔案大小 -->

    <httpRuntime maxRequestLength="1024" requestValidationMode="2.0" />

  </system.web>

三個都改完後,發現還是不行,然後我發現是我的web.config中的程式碼有錯誤。這個段程式碼必須放在<loctaion>...</location>中,而不是<location path="ajaxpro">

我的配置中不知道為什麼有個<location path="ajaxpro">.我把其中的<httpRuntime....>程式碼取出來,再寫一個<location>就好了。

 <location path="ajaxpro">
  <system.web>
   <httpHandlers>
  ......
  <location>
    <system.web>
      <httpRuntime executionTimeout="8000" maxRequestLength="50000" useFullyQualifiedRedirectUrl="false"/>
    </system.web>
  </location>

 我原來是Xp的系統,換成win7後,釋出完成,本地電腦執行又發現錯誤了。按照這個流程就解決了。

改過來後,又發現錯誤,按照下邊的文章就解決了。