【问题标题】:NetworkError: 500 Internal Server Error when JSON requested on hostingNetworkError:在主机上请求 JSON 时出现 500 内部服务器错误
【发布时间】:2015-05-13 14:23:59
【问题描述】:

我在 asp.net mvc 中的应用程序有问题。 在我的应用程序中,我使用了在 JSON 数组中请求的 FullCalendar jQuery 事件。 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 Internal Server Error(在 firefox 的 firebug 中观看)。我在萤火虫中发现答案的标题有一个 Content-Type text/html; charset=utf-8 而不是 内容类型应用程序/json; charset=utf-8 - 就像在本地主机上一样。 会是什么?

请帮帮我。

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

致梅拉斯佩拉斯 我像你说的那样添加到我的配置代码中。就是这样。

<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

到胚胎发育: 你的参数不会改变任何东西。

在 Visual Studio 的本地主机上,我有:

在我的答案标题中:

    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

【问题讨论】:

  • 您检查过 IIS 中的 mime/type 吗??
  • 感谢您的回答。我从您的链接中读取了信息,但我的应用程序部署在主机上,我无法访问服务器的配置。还有其他方法可以解决吗?例如在我的应用程序的本地 Web.config 中?
  • 我用 web.config 设置更新了我的答案
  • 我用你的线索更新我的问题。那么没有配置IIS就没有办法修复它吗?那么这种情况下就没有解决办法了吗?
  • 也许您遇到了真正的错误,您可以关闭 ASP.net 的自定义错误。

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


【解决方案1】:

我相信您会希望像这样指定 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/

【讨论】:

  • 这是否将答案标题更改为不包含 Content-Type 文本/html?您在本地获得的有效内容响应是什么?远程获得的无效内容响应是什么?
  • 我更新了我的问题,回答了你的问题。
【解决方案2】:

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

Run as command 以管理员身份运行 IIS Manager -> 在 Run as 中输入:inetmgr

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

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

  2. 单击 HTTP 标头选项卡。

  3. 单击 Mime 类型。
  4. 点击新建。
  5. 在“扩展名”框中,键入文件扩展名。
  6. 在 MIME 类型框中,键入与计算机上定义的文件类型完全匹配的描述。如果您定义了已在更高级别定义的 MIME 类型,系统将提示您选择 MIME 类型应驻留的级别。
  7. 点击确定。

或者在您的网络配置中,您可以这样做:

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

希望对你有帮助,

问候

【讨论】:

    猜你喜欢
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    相关资源
    最近更新 更多