我有一個文件代理IHttpHandler
以確保身份驗證和記錄請求。它工作正常,在開發服務器上和IIS 6在IIS 7,我有兩個問題:IIS 7中的文件代理處理程序
微軟辦公軟件(Word,Excel文檔...)將與
OPTION
和PROPFIND
動詞WebDAV請求。 ASP.NET因爲不支持它們而引發異常。有沒有辦法在IIS級別禁用這些動詞,以便它永遠不會到達ASP.NET?我猜它會返回一個405 Method Not Allowed
錯誤(http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error)。IIS 7打開分塊編碼。在這種情況下,
Content-Length
標題無效,顯然IIS 7將其刪除:http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.4.4。但是,它也會刪除Content-Type
標題,導致文件在瀏覽器中顯示爲文本。那麼,如何阻止IIS 7刪除Content-Type
,或者如何關閉此頁面的分塊編碼?以下是您要比較的響應標題。
開發服務器響應:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Thu, 23 Dec 2010 17:57:09 GMT
X-AspNet-Version: 2.0.50727
Content-Length: 68096
Content-Disposition: inline; filename=test.doc
Cache-Control: private
Last-Modified: Thu, 23 Dec 2010 09:14:18 GMT
Content-Type: application/msword
Connection: Close
IIS 7響應:
HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Last-Modified: Thu, 23 Dec 2010 09:30:31 GMT
Server: Microsoft-IIS/7.5
Content-Disposition: inline; filename=test.doc
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 23 Dec 2010 17:57:59 GMT
嘗試```StaticFileHandler```而不是``DefaultHttpHandler``` – 2013-03-14 17:02:23