开发者

URL routing, rewrite path but keep mimetype

开发者 https://www.devze.com 2022-12-20 21:05 出处:网络
I have implemented my own IRouteHandler for URL routing. For files without extension it will try to load the filename as a Page from the Pages directory with:

I have implemented my own IRouteHandler for URL routing.

For files without extension it will try to load the filename as a Page from the Pages directory with:

return (IHttpHandler) BuildManager.CreateInstanceFromVirtualPath(path, typeof(Page));

How开发者_如何学运维ever there are also images and css files (with relative paths) that need to be translated to the correct url. I try to service those files with:

try {
   HttpContext.Current.Server.Transfer(fileName);
} catch (HttpException) {
   throw new HttpException(404, "file not found");
}

This works fine (in Internet Explorer), however Firefox is giving me an error:

Styles.css was not loaded because its MIME type, "text/html", is not "text/css".

Is this caused by the Server.Transfer?

What should I use to redirect the file? Response.Redirect is visible to the client.


I've found a solution, .NET 3.5 and IIS7 introduced a new method: Server.TransferRequest.

With the TransferRequest method the request is sent back through the IIS pipeline. http://msdn.microsoft.com/en-us/library/aa344902.aspx

Firefox is happily accepting my CSS files again.

0

精彩评论

暂无评论...
验证码 换一张
取 消