0

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 ?

Arbejdsglæde
  • 12,249
  • 20
  • 69
  • 137

1 Answers1

1

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.aspx WebForm which I guess returns HTML and not javascript. Or if it does return javascript it doesn't set the proper Content-Type header to text/javascript.

That's why Chrome complains: you are pointing the src attribute 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 the Network tab when analyzing the different HTTP requests that are being sent from the browser.

Darin Dimitrov
  • 960,118
  • 257
  • 3,196
  • 2,876
  • Hi Darin Thanks , you are right my page type is text/html. I change in script type field by now I have Resource interpreted as Script but transferred with MIME type text/html Do I need do something more ? – Arbejdsglæde Dec 07 '12 at 12:05
  • You should change the response Content-Type header returned by your `adminDashboard.aspx` page, not change the ` – Darin Dimitrov Dec 07 '12 at 14:53
  • I agree with you absolutely, but I need to have some legacy behavior on some pages, and idea is to start some big long process on server side after user input, but user must see page with message that his request under process and after this user must be redirected to other page (dashboard.aspx) Previous team make is in stupid way they had created 3 pages 1 with user-form that redirect you to 2 page where you see picture with loading process on page load event on this page exit event what emulate user click on button, this button starting this proccess and redirect you to dashboard page – Arbejdsglæde Dec 08 '12 at 22:38
  • on server event. I have decided to redo this behavior with using ashx, but redirection is my problem now. – Arbejdsglæde Dec 08 '12 at 22:40
  • 1
    @cleric, if you want this to work, the server side script you are redirecting to must return javascript. Otherwise you shouldn't be putting it inside a ` – Darin Dimitrov Dec 09 '12 at 22:22