Asp.net mvc ASP.net MVC项目中存储在文件系统上的照片出现零星访问被拒绝错误 一些背景
我有一个ASP.NETMVC4Web应用程序,它提供了对大量照片的访问。每个照片都从MySQL表中获得一个唯一的ID,然后以十六进制形式组成文件名并存储在文件系统的文件夹中 例如: D:\Photos\69F.jpg 在整个应用程序中,将显示使用原始照片创建的不同大小的缩略图。由于缩略图很少发生更改,因此,如果有更改,缩略图将以以下格式创建并保存到同一文件系统文件夹中。(这意味着90%的时间,照片可以直接返回,无需任何图像处理)Asp.net mvc ASP.net MVC项目中存储在文件系统上的照片出现零星访问被拒绝错误 一些背景,asp.net-mvc,filesystems,photo,access-denied,Asp.net Mvc,Filesystems,Photo,Access Denied,我有一个ASP.NETMVC4Web应用程序,它提供了对大量照片的访问。每个照片都从MySQL表中获得一个唯一的ID,然后以十六进制形式组成文件名并存储在文件系统的文件夹中 例如: D:\Photos\69F.jpg 在整个应用程序中,将显示使用原始照片创建的不同大小的缩略图。由于缩略图很少发生更改,因此,如果有更改,缩略图将以以下格式创建并保存到同一文件系统文件夹中。(这意味着90%的时间,照片可以直接返回,无需任何图像处理) 缩略图正常-D:\Photos\69F\u t.jpg 缩略图-
- 缩略图正常-D:\Photos\69F\u t.jpg
- 缩略图-D:\Photos\69F_tm.jpg
Function Thumb(Optional ByVal id As Integer = Nothing)
Dim thumbImage As WebImage
Dim dimension As Integer = 200
' Create the image paths
Dim imageOriginal As String = System.Configuration.ConfigurationManager.AppSettings("imageStore") + Hex(id) + ".jpg"
Dim imageThumb As String = System.Configuration.ConfigurationManager.AppSettings("imageStore") + Hex(id) + "_t.jpg"
' If no image is found, return not found
If FileIO.FileSystem.FileExists(imageOriginal) = False Then
Return New HttpNotFoundResult
End If
' If a thumbnail is present, check its validity and return it
If FileIO.FileSystem.FileExists(imageThumb) = True Then
thumbImage = New WebImage(imageThumb)
' If the dimensions are correct, simply return the image
If thumbImage.Width = dimension Then
thumbImage = Nothing
Return File(imageThumb, System.Net.Mime.MediaTypeNames.Image.Jpeg)
End If
End If
' If we get this far, either the thumbnail is not the right size or does not exist!
thumbImage = New WebImage(imageOriginal)
' First we must make the image a square
If thumbImage.Height > thumbImage.Width Then
' Portrait
Dim intPixelRemove As Integer
' Determine the amount to crop off the top and bottom
intPixelRemove = (thumbImage.Height - thumbImage.Width) / 2
thumbImage.Crop(intPixelRemove, 0, intPixelRemove, 0)
Else
' Landscape
Dim intPixelRemove As Integer
' Determine the amount to crop off the top and bottom
intPixelRemove = (thumbImage.Width - thumbImage.Height) / 2
thumbImage.Crop(0, intPixelRemove, 0, intPixelRemove)
End If
thumbImage.Resize(dimension + 2, dimension + 2, True, True)
thumbImage.Crop(1, 1, 1, 1)
thumbImage.Save(imageThumb)
thumbImage = Nothing
Try
Return File(imageThumb, System.Net.Mime.MediaTypeNames.Image.Jpeg)
Catch ex As Exception
Return New HttpNotFoundResult
End Try
End Function
问题
我很确定有什么东西使文件处于打开状态,因此不允许应用程序将文件返回到浏览器,但不管它是什么,它是非常零星的,因为这在90-95%的调用中都可以正常工作
这或问题是由于多人试图访问同一文件时并发造成的