Issues accessing assets in IIS Virtual Directory with FileHander

25 Views Asked by At

I have a legacy Web-forms web application. This application uses a folder (outside of the application) for the site.master and related assets (css/js/images). I am trying to address a layout shift issue and want to serve all assets through a file-handler (DX.ashx) as I'm using DevExpress and some of the DevExpress assets are added at runtime which cause the layout shift.

When I use the virtual directory (e.g. \myvirtualdirectory\site.css) in a normal link tag, it works just fine (except for the layout shift):

<link href="~/myvirtualdirectory/site.css" rel="stylesheet" /> 

When I add the file through the handler, I get an error related to a 404, here's the ASP markup:

<link href="DX.ashx?cssfile=~/myvirtualdirectory/site.css" rel="Stylesheet" />

Here's the error in the browser console.

Refused to apply style from 'https://domain/DX.ashx?cssfile=~/myvirtualdirectory/site.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

If I access the file through the path, I see a generic 500 error.

To ensure that the file handler works properly, I placed the css file in the root of the application and adjusted the file handler markup accordingly, it works perfectly.

<link href="DX.ashx?cssfile=~/site.css" rel="Stylesheet" />

I suspect it's a permissions issue within IIS. If I replicate this in Visual Studio, using IISExpress, it works just fine. It's only in the test and production environment that this becomes a significant issue.

What are some troubleshooting steps I can take, does anyone have any suggestions?

0

There are 0 best solutions below