Pass a request back to IIS inside a ActionResult

229 views Asked by At

I'm pretty sure the answer is "you can't do this", but if so, ASP.NET MVC is horribly flawed.

I have an ActionResult which needs to serve a static file (the filename is determined in code). For performance reasons (and because I don't feel like re-implementing the HTTP spec for accept-bytes and caching headers), I want to hand the request off to IIS. Like context.RewritePath() from an HttpModule does when you give it the name of a static file.

Except this needs to happen inside an ActionResult, not during PostAuthorizeRequest.

Looking at the FileStreamResult and FilePathResult classes, it's obvious they only implement HTTP 200. TransmitFile() is nice and all, but it isn't kernel caching, and it doesn't handle Accept-bytes, If-Modified-Since, or Etags.

We've been told for almost a decode how much better IIS is at serving files, and how important the Integrated Pipeline was, how evil wildcard mapping on IIS6 was for performance, etc.

Now we're back in the same boat - no way to let IIS serve a static file from an ActionResult. (NO, TransmitFile doesn't count).

I've even started seeing MS recommend that you put static content on a separate server.

Please tell me I'm wrong, that there's a magic method somewhere that does this. Or has the Integrated Pipe Dream been killed by MVC?

1

There are 1 answers

3
Daniel A. White On

Why don't you use Redirect or RedirectPermanent?