从/ Content /文件夹

时间:2015-06-09 09:59:17

标签: asp.net-mvc angularjs

我想从我的/ Content /文件夹中提供静态内容。最初我收到404错误,因此将mime类型添加到我的WebConfig中,如下所示:

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

现在我可以通过直接URL访问此内容(即在我的浏览器中查看),但是当我使用ajax(AngularJS特定)请求时(URL完全相同),我收到400 Bad Request错误。

这里发生了什么?

网址为/content/help/schedules.markdown,我使用以下代码来请求

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

修改

我尝试使用jQuery请求数据并且它有效!显然它是唯一导致问题的Angular!

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

编辑2 - 标题 AngularJS请求标头:

  

接受:application / json,text / plain, / Accept-Encoding:gzip,   deflate,sdch Accept-Language:en-GB,en-US; q = 0.8,en; q = 0.6   缓存控制:无缓存连接:保持活动状态   饼干:csrftoken = Q53T7sBOlAgpNSGh7QJ43LSy1CzUPdmV;   AUTH = Z3Vlc3Q6Z3Vlc3Q%3D; __ngDebug = TRUE;   __RequestVerificationToken = 9ox1j5vvUHDyflvTarxzaLbZumwT0qnWvxT5fXbX1BTwhZwms_tUJe-9Du-R0-SttzuONVd3MeYRpCYCDit5rHzt7v1sK-C9SCsjZ0rE2j41;   米= 34e2:| 47ba:T | 4A01:T | 745A:T | 2A03:T | 54E1:T | 77cb:T | CA3:T | 4d66:240 | 18c3:T | 1d98:T | 79d4:图表| 640C :介质| 678E:600%7C5 | 5cf4:T | 3a8e:图表| 54ae:介质| 29ac:600%7C5;   .ASPXAUTH = DA9F6F0DC7114A0A7B1C7A8E0050A4C4FF4D0F2553F0AAE9407DF141D9ED9D930897E28A47F4794C2C5C63A7EA64AEB50CA184B89F07769FEE2241E6292483666C42187BD1DBA66C806665593D20A1FBFCCC9584213D869B58F75E992DD7C77F05FC55BF2CB30AF32165A98C3272D7071610BE0321393B5713C313E5E12FFEE0368F37585210C9C270E57A6D66953FA4ABC7AE7D50905D05BDD7D8A4D0EDF6186F6795263783D973EC9B1C4E11BF1788A596401202E697FC6EB0AFB7D7A6D4DD   主机:localhost:1904 If-Modified-Since:0 Pragma:no-cache   引用者:http://localhost:1904/settings/schedules/   User-Agent:Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36   (KHTML,像Gecko一样)Chrome / 43.0.2357.81 Safari / 537.36   X-请求-随着:XMLHttpRequest的

jQuery请求标头:

  

接受: / 接受编码:gzip,deflate,sdch   Accept-Language:en-GB,en-US; q = 0.8,en; q = 0.6 Connection:keep-alive   饼干:csrftoken = Q53T7sBOlAgpNSGh7QJ43LSy1CzUPdmV;   AUTH = Z3Vlc3Q6Z3Vlc3Q%3D; __ngDebug = TRUE;   __RequestVerificationToken = 9ox1j5vvUHDyflvTarxzaLbZumwT0qnWvxT5fXbX1BTwhZwms_tUJe-9Du-R0-SttzuONVd3MeYRpCYCDit5rHzt7v1sK-C9SCsjZ0rE2j41;   米= 34e2:| 47ba:T | 4A01:T | 745A:T | 2A03:T | 54E1:T | 77cb:T | CA3:T | 4d66:240 | 18c3:T | 1d98:T | 79d4:图表| 640C :介质| 678E:600%7C5 | 5cf4:T | 3a8e:图表| 54ae:介质| 29ac:600%7C5;   .ASPXAUTH = DA9F6F0DC7114A0A7B1C7A8E0050A4C4FF4D0F2553F0AAE9407DF141D9ED9D930897E28A47F4794C2C5C63A7EA64AEB50CA184B89F07769FEE2241E6292483666C42187BD1DBA66C806665593D20A1FBFCCC9584213D869B58F75E992DD7C77F05FC55BF2CB30AF32165A98C3272D7071610BE0321393B5713C313E5E12FFEE0368F37585210C9C270E57A6D66953FA4ABC7AE7D50905D05BDD7D8A4D0EDF6186F6795263783D973EC9B1C4E11BF1788A596401202E697FC6EB0AFB7D7A6D4DD   主持人:localhost:1904 Referer:http://localhost:1904/settings/schedules/   User-Agent:Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36   (KHTML,像Gecko一样)Chrome / 43.0.2357.81 Safari / 537.36   X-请求-随着:XMLHttpRequest的

1 个答案:

答案 0 :(得分:1)

问题在于AngularJS标头中的此标头:

  

If-Modified-Since:0

您应该通过将此标头设置为undefined来删除此标头:

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