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));
However 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.