Hello I aspx page with next call for my ashx
<script type="text/javascript" src="/Handlers/MyRedirect.ashx">
</script>
Inside of MyRedirect I do some hard logic and try to redirect to other page of my side
it looks like:
public class MyRedirect : HttpTaskAsyncHandler, IReadOnlySessionState
{
public override async Task ProcessRequestAsync(HttpContext context)
{
//some logic here with out any output
//context.Response.ContentType = "application/x-javascript";
context.Response.Redirect("/adminDashboard.aspx", false);
}
}
but in Chrome I getting error
Resource interpreted as Script but transferred with MIME type text/html:
What I do wrong ? How to fix it thank ?
The page you are redirecting to must return javascript and set appropriate response content-type header. In the example you have shown you seem to be redirecting to some
/adminDashboard.aspxWebForm which I guess returns HTML and not javascript. Or if it does return javascript it doesn’t set the proper Content-Type header totext/javascript.That’s why Chrome complains: you are pointing the
srcattribute of your<script>tag to a server side handler which doesn’t set the expected and correct content type.So if you have to perform this redirect make sure that at the end of the day the page you have redirected to returns valid javascript and that it sets the Content-Type header to
text/javascript. You could very easily see this in theNetworktab when analyzing the different HTTP requests that are being sent from the browser.