tags:

views:

125

answers:

2

Is it possible to programmatically resolve a URL to a file using ASP.NET and IIS? Specifically I'd like the file to be outside of my Virtual Directory (could be anywhere on the local file system). So if a URL comes in like http://mysite/somepicture.jpg I'd like to be able to return c:\mypicture.jpg. I looked into creating an IHttpModule for URL rewriting but that isn't quite what I need - it's limited to URLs within the existing site.

+2  A: 

You cannot achieve it by URL rewriting as the file is not hosted on your Web site. You should use Response.WriteFile method in an HttpModule or HttpHandler to manually stream the file to the user.

Mehrdad Afshari
A: 

I would like to add to Mehrdad's response by saying that you need to make sure your app has rights to the folder the files you want live in. That way you can dish it out as Mehrdad suggested.

Al Katawazi