【问题标题】:FilePathResult with network path throws COMException (The handle is invalid)带有网络路径的 FilePathResult 引发 COMException(句柄无效)
【发布时间】:2013-05-31 13:31:44
【问题描述】:

我正在像这样使用 FilePathResult:

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: my@user.com
    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 世界的其他地方没有发现这个问题,所以我想我会在这里问。

【问题讨论】:

    标签: asp.net-mvc exception networking comexception


    【解决方案1】:

    现在说可能还为时过早,但是,似乎从 FilePathResult 更改为 FileContentResult 已经解决了问题。

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

    我不确定 FilePathResult 最终会在内部做什么,但是使用 ReadAllBytes 读取文件似乎可以避免这个问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 2014-08-04
    • 1970-01-01
    • 2019-08-23
    • 2016-01-28
    相关资源
    最近更新 更多