Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm building a simple CMS for one B2B application. The user can upload/browse an image, but those images are stored outside of IIS (my application is located on drive C, and images are stored on drive D).

My plan is to create a custom route for page files, and then simply load images using FileController

FileController:

public FilePathResult PageFiles(string fileName)
{
    var dir = Server.MapPath("/some_protected_area/gallery");
    var path = Path.Combine(dir, fileName);
    return File(path, "image/jpg");
}

Custom route:

routes.MapRoute(
    null,
    "Files/PageFiles/{fileName}",
    new { controller = "File", action = "PageFiles", fileName = UrlParameter.Optional },
    new[] { "DemoApp.Web.Controllers" }
    );

When I access http://localhost:58891/Files/PageFiles/image-1.jpg I get 404.

Detailed Error Information:

Modeule: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error code: 0x80070002

When I access: http://localhost:58891/Files/PageFiles?fileName=image-1.jpg everything works fine, but I don't want to send fileName in query string, and fileName must contain the extension (.jpg, .pdf, etc.)

Can I somehow disable StaticFile handler for custom routes?

Any help would be greatly appreciated!

share

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.