I have an ASP.NET MVC 1.0 application running on Windows Server 2003 IIS 6.0.
I just added a new feature that lets users upload files to the server. I also added a page that displays a list of the files uploaded by that user.
The problem is when someone clicks to view the file, I get the following error: The system cannot find the file specified.
I have verified everything is correct and I can't figure this out for the life of me.
I added this code to the routing section thinking that may have something to do with it but it hasn't helped.
routes.RouteExistingFiles = false;
routes.IgnoreRoute("App_Data/Uploads/{*pathInfo}");
Any help would be greatly appreciated.
Files stored in App_Data
folder cannot be directly accessed by clients. ASP.NET blocks acces to it. So no need to add any ignore routes for this special folder, you cannot use an url like this /App_Data/Uploads/foo.txt
. If you want serving files from this folder you need to write a controller action will read the file from the physical location and return it to the client:
public ActionResult Download(string id)
{
// use the id and read the corresponding file from it's physical location
// and then return it:
return File(physicalLocation, mimeType);
}
and then use:
<%= Html.ActionLink("download report", "download", new { id = 123 }) %>
Try adding ignore routes (so that they're just served without going through routing)
routes.IgnoreRoute("{file}.txt");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With