NetworkError:在托管时请求JSON时出现500内部服务器错误

时间:2015-05-13 14:23:59

标签: jquery asp.net json asp.net-mvc iis

我在asp.net mvc中的应用程序有问题。 在我的应用程序中,我使用JSON数组中请求的FullCalendar jQuery whith事件。 jQueryCalendar如下所示。

function renderCalendar() {
    $("#cal").fullCalendar({
        header: {
            left: 'prev, next today',
            center: 'title',
            right: 'agendaDay, month'
        },
        height: 'auto',
        fixedWeekCount: false,
        firstDay: 1,
        editable: false,
        allDaySlot: false,
        selectable: true,
        slotMinutes: 15,
        axisFormat: 'HH:mm',
        eventLimit: true,
        businessHours: {                
            start: '07:00',
            end: '23:00'
        },
        eventLimitClick: 'day',
        views: {
            month: {
                eventLimit: 8
            }
        },
        lang: 'pl',
        displayEventEnd: true,
        timeFormat: {
            month: "HH:mm"
        },

        events: {
            url: '/Schedules/GetEvents/',
            type: 'GET',
            data: {
                department_term: current_department,
            }
        },
        dayClick: function (date, jsEvent, view) {
            $('#cal')
                .fullCalendar('changeView', 'agendaDay');

            $('#cal')
                .fullCalendar('gotoDate', date.format());
        }
    });

我的控制器操作如下所示:

    public JsonResult GetEvents(DateTime start, DateTime end, string   department_term)
        {
            operations to generating listOfEvents
            var results = listOfEvents.ToArray();
            return Json(results, JsonRequestBehavior.AllowGet);
        }

在我的视觉中,一切都在本地主机上正常工作。但我必须将应用程序部署到somme.com,现在如果我打开日历,我会收到NetworkError:500内部服务器错误(在firefox中查看firebug)。我在firebug中发现答案的标题是Content-Type text / html; charset = utf-8而不是 Content-Type application / json; charset = utf-8 - 就像本地主机一样。 它可能是什么?

请帮帮我。

http://staff-net.somee.com/Schedules/Calendar

致melaspelas 我像你说的那样添加了我的配置代码。就是这样。

<system.webServer>      
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>  
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>

但那仍然不起作用。

我仍然在我的答案标题中:

Content-Length      75
Content-Type        text/html
Date        Fri, 15 May 2015 10:45:26 GMT
Server      Microsoft-IIS/8.5

并在请求标题中:

Accept      application/json, text/javascript, */*; q=0.01
Accept-Encoding     gzip, deflate
Accept-Language     pl,en-US;q=0.7,en;q=0.3
Content-Type        application/json; charset=utf-8
Cookie      b=b; ... <lot of text>
Host        staff-net.somee.com
Referer     http://staff-net.somee.com/Schedules/Calendar
User-Agent      Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
X-Requested-With    XMLHttpRequest

对于peinearydevelopment: 您的参数不会改变任何内容。

在Visual Studio中的localhost上我有:

在我的答案标题中:

    Cache-Control   private, s-maxage=0
Content-Length  15263
Content-Type    application/json; charset=utf-8
Date    Fri, 15 May 2015 15:16:56 GMT
Server  Microsoft-IIS/8.0
X-AspNet-Version    4.0.30319
X-AspNetMvc-Version 5.0
X-Powered-By    ASP.NET
X-SourceFiles   =?UTF-8?B?QzpcVXNlcnNcbGtvemxvd3NraVxEb2N1bWVudHNcVmlzdWFsIFN0dWRpbyAyMDEzXFByb2plY3RzXFNUQUZGLk5FVFxTVEFGRi5ORVRcU2NoZWR1bGVzXEdldEV2ZW50c1w
=?=

并在请求标题中:

    Accept  application/json, text/javascript, */*; q=0.01
    Accept-Encodingg     zip, deflate
    Accept-Language pl,en-US;q=0.7,en;q=0.3
Cookie  __RequestVerificationToken=LI...
Host    localhost:50206
Referer http://localhost:50206/Schedules/Calendar
User-Agent  Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
X-Requested-With    XMLHttpRequest

在托管上我有:

回答标题

Cache-Control   private, s-maxage=0
Content-Length  2903
Content-Type    text/html; charset=utf-8
Date    Fri, 15 May 2015 15:27:00 GMT
Server  Microsoft-IIS/8.5
X-AspNet-Version    4.0.30319
X-AspNetMvc-Version 5.0
X-Frame-Options SAMEORIGIN
X-Powered-By    ASP.NET

请求标题:

Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language pl,en-US;q=0.7,en;q=0.3
Cookie  b=b; b=b; questVerificationToke...
Host    staff-net.somee.com
Referer http://staff-net.somee.com/Schedules/Calendar
User-Agent  Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
X-Requested-With    XMLHttpRequest

2 个答案:

答案 0 :(得分:0)

我相信你会想要像这样指定Content-Type:

events: {
  url: '/Schedules/GetEvents/',
  type: 'GET',
  contentType: 'application/json; charset=utf-8'
  data: {
    department_term: current_department,
}

这个插件似乎在后台使用$ .ajax。您可以按照此处记录的设置对其进行设置:http://api.jquery.com/jQuery.ajax/

答案 1 :(得分:-1)

我猜你需要将mime类型的json添加到你的IIS,请检查一下:

以命令运行以管理员身份运行IIS管理器 - &gt;在运行方式类型:inetmgr

然后(check this link了解详细步骤)

  1. 在IIS管理器中,右键单击要为其添加MIME类型的网站或网站目录,然后单击“属性”。

  2. 单击“HTTP标头”选项卡。

  3. 点击Mime类型。
  4. 点击新建。
  5. 在“扩展名”框中,键入文件扩展名。
  6. 在“MIME类型”框中,键入与计算机上定义的文件类型完全匹配的说明。如果定义已在更高级别定义的MIME类型,系统将提示您选择MIME类型应驻留的级别。
  7. 单击“确定”。
  8. 或者在您的网络配置中,您可以执行此操作:

      <system.webServer>
        <staticContent>
          <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
      </system.webServer>
    

    我希望这有帮助,

    此致