首页 > 解决方案 > 当 JsonRequestBehavior 设置为 AllowGet 时如何在 IIS 上允许 GET 请求

问题描述

我的 asp.net mvc web 应用程序和应用程序在 localhost 上运行良好,但是在 IIS 服务器上部署后 Json Get 请求被阻止。我将 JsonRequestBehavior 设置为 AllowGet。我允许 IIS 上对所有 http 请求的请求,但仍然出现此错误:

此请求已被阻止,因为在 GET 请求中使用敏感信息可能会泄露给第三方网站。要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。”

 using (cmd = new OracleCommand(query, con))
                {
                    con.Open();
                    OracleDataAdapter sda = new OracleDataAdapter(cmd);
                    sda.Fill(dt1);
                    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                    Dictionary<string, object> row;

                    foreach (DataRow dr in dt1.Rows)
                    {
                        row = new Dictionary<string, object>();
                        foreach (DataColumn col in dt1.Columns)
                        {
                            row.Add(col.ColumnName, dr[col]);
                        }
                        rows.Add(row);
                    }
                    return Json(rows, JsonRequestBehavior.AllowGet);
                }

IIS 上是否有任何用于过滤请求的设置?

编辑:

将 GET Verb 添加到 IIS 设置后,我收到了新错误:

System.ArgumentException:超出 RecursionLimit。

标签: c#jsonasp.net-mvciis

解决方案


您可以通过此链接查看它https://www.compilemode.com/2015/10/request-has-been-blocked-In-mvc-json-result.html

我无法清楚答案,因为我看不到您的所有代码

[HttpGet]
public JsonResult GetData()
{
    List<string> a = new List<string>();
    a.Add("A");

    return Json(a, JsonRequestBehavior.AllowGet);
}

推荐阅读