2

I want to serve up static content from my /Content/ folder. Initially I received a 404 error so added the mime type to my WebConfig like so:

<staticContent>
  <mimeMap fileExtension=".markdown" mimeType="text/x-markdown" />
</staticContent>

Now I can access this content via direct URL (i.e. see it in my browser) but when I use ajax (AngularJS to be specific) for the request (the URL is exactly the same) I receive a 400 Bad Request error.

What is happening here?

The URL is /content/help/schedules.markdown and I use the following code to request it

return $http({
    method: 'GET',
    url: '/content/help/schedules.markdown'
})

Edit

I tried to request the data using jQuery and it worked! So apparently its only Angular that is causing a problem!

$.get("/content/help/schedules.markdown",function(yo){console.log(yo)});

Edit 2 - Headers AngularJS request headers:

Accept:application/json, text/plain, / Accept-Encoding:gzip, deflate, sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Cache-Control:no-cache Connection:keep-alive Cookie:csrftoken=Q53T7sBOlAgpNSGh7QJ43LSy1CzUPdmV; auth=Z3Vlc3Q6Z3Vlc3Q%3D; __ngDebug=true; __RequestVerificationToken=9ox1j5vvUHDyflvTarxzaLbZumwT0qnWvxT5fXbX1BTwhZwms_tUJe-9Du-r0-SttzuONVd3MeYRpCYCDit5rHzt7v1sK-C9SCsjZ0rE2j41; m=34e2:|47ba:t|4a01:t|745a:t|2a03:t|54e1:t|77cb:t|ca3:t|4d66:240|18c3:t|1d98:t|79d4:chart|640c:medium|678e:600%7C5|5cf4:t|3a8e:chart|54ae:medium|29ac:600%7C5; .ASPXAUTH=DA9F6F0DC7114A0A7B1C7A8E0050A4C4FF4D0F2553F0AAE9407DF141D9ED9D930897E28A47F4794C2C5C63A7EA64AEB50CA184B89F07769FEE2241E6292483666C42187BD1DBA66C806665593D20A1FBFCCC9584213D869B58F75E992DD7C77F05FC55BF2CB30AF32165A98C3272D7071610BE0321393B5713C313E5E12FFEE0368F37585210C9C270E57A6D66953FA4ABC7AE7D50905D05BDD7D8A4D0EDF6186F6795263783D973EC9B1C4E11BF1788A596401202E697FC6EB0AFB7D7A6D4DD Host:localhost:1904 If-Modified-Since:0 Pragma:no-cache Referer:http://localhost:1904/settings/schedules/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36 X-Requested-With:XMLHttpRequest

jQuery request headers:

Accept:/ Accept-Encoding:gzip, deflate, sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Connection:keep-alive Cookie:csrftoken=Q53T7sBOlAgpNSGh7QJ43LSy1CzUPdmV; auth=Z3Vlc3Q6Z3Vlc3Q%3D; __ngDebug=true; __RequestVerificationToken=9ox1j5vvUHDyflvTarxzaLbZumwT0qnWvxT5fXbX1BTwhZwms_tUJe-9Du-r0-SttzuONVd3MeYRpCYCDit5rHzt7v1sK-C9SCsjZ0rE2j41; m=34e2:|47ba:t|4a01:t|745a:t|2a03:t|54e1:t|77cb:t|ca3:t|4d66:240|18c3:t|1d98:t|79d4:chart|640c:medium|678e:600%7C5|5cf4:t|3a8e:chart|54ae:medium|29ac:600%7C5; .ASPXAUTH=DA9F6F0DC7114A0A7B1C7A8E0050A4C4FF4D0F2553F0AAE9407DF141D9ED9D930897E28A47F4794C2C5C63A7EA64AEB50CA184B89F07769FEE2241E6292483666C42187BD1DBA66C806665593D20A1FBFCCC9584213D869B58F75E992DD7C77F05FC55BF2CB30AF32165A98C3272D7071610BE0321393B5713C313E5E12FFEE0368F37585210C9C270E57A6D66953FA4ABC7AE7D50905D05BDD7D8A4D0EDF6186F6795263783D973EC9B1C4E11BF1788A596401202E697FC6EB0AFB7D7A6D4DD Host:localhost:1904 Referer:http://localhost:1904/settings/schedules/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36 X-Requested-With:XMLHttpRequest

Chris
  • 26,744
  • 48
  • 193
  • 345
  • Is it cross origin and did you read about cors? – lin Jun 09 '15 at 10:21
  • Angular & jQuery calling the same url? Did you checked this in your network log? – lin Jun 09 '15 at 11:17
  • I'm checking in Chromes network panel. jQuery appends `?_=1433848661501` to prevent caching. If I copy the exact URL jQuery succeeds on and put it into angular, it fails. If I open that URL in a new tab in my browser it works also! – Chris Jun 09 '15 at 11:19
  • In fact, if I make Angular try to load anything from `/content/` it fails (even `site.css` which I use on every page). $http works when calling a controller though! – Chris Jun 09 '15 at 11:21
  • Hmm, compare your headers. You see any difference? Is the response blocked by the browser or by angular? – lin Jun 09 '15 at 11:26
  • Blocked by the server I think (the response sends 400) – Chris Jun 09 '15 at 11:44

1 Answers1

1

the problem is with this header in AngularJS headers:

If-Modified-Since:0

you should remove this header from this specific request by setting it to undefined:

$http.get($scope.url, { headers: { 'If-Modified-Since': undefined } })
Ghasem
  • 79
  • 4