2013-05-31 69 views
3

我使用FilePathResult像這樣:FilePathResult與網絡路徑拋出收到COMException(句柄是無效)

return new FilePathResult(path, "text/xml"); 

我的路是我們的網絡上其他地方的路徑。這會導致服務器錯誤。當我檢查服務器上的事件日誌中我可以看到這個錯誤項:

TransmitFile failed. File Name: \\our\path\to\the\file\filename.dfxp, HRESULT: 0x80070005 

同時在事件查看器中記錄以及警告:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 5/30/2013 4:05:03 PM 
Event time (UTC): 5/30/2013 9:05:03 PM 
Event ID: d77e5b799b87455f9f4daa7367f1bad2 
Event sequence: 33 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/3/ROOT-1-130144212630349792 
    Trust level: Full 
    Application Virtual Path:/
    Application Path: C:\inetpub\wwwroot\my.site.folder\ 
    Machine name: MyMachine 

Process information: 
    Process ID: 3408 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\my.site.name 

Exception information: 
    Exception type: COMException 
    Exception message: The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE)) 



Request information: 
    Request URL: http://my.site.com/Download/fca4fd06-d942-4ee8-8fe3-7ec7aa26938f 
    Request path: /Download/fca4fd06-d942-4ee8-8fe3-7ec7aa26938f 
    User host address: 10.0.70.17 
    User: [email protected] 
    Is authenticated: True 
    Authentication Type: Forms 
    Thread account name: OURDOMAIN\SA-ACCOUNT 

Thread information: 
    Thread ID: 14 
    Thread account name: OURDOMAIN\SA-ACCOUNT 
    Is impersonating: False 
    Stack trace: 

我的服務帳戶的應用程序正在運行下具有對文件夾位置的讀取權限。我沒有發現在ASP.NET MVC世界其他地方提到的這個問題,所以我想我會問這裏。

回答

4

可能還爲時過早,但是,它彷彿從FilePathResult更改爲FileContentResult已經解決了這一問題。

var fileBytes = System.IO.File.ReadAllBytes(fileInfo.FullName); 
return new FileContentResult(fileBytes, "text/xml") 

我不知道什麼FilePathResult結束了在內部做,但是,讀文件,ReadAllBytes似乎在迴避這個問題。

+1

不錯,這對我很有用。謝謝 – Francisco

+0

ReadAllBytes將整個文件讀入內存,對大文件不好。此解決方案沒有:http://stackoverflow.com/questions/2645302/impersonation-in-asp-net-mvc – mxmissile

+0

這工作soooooo以及;) –

相關問題