在使用IIS Express的localhost上,当我将其复制到服务器2012上的IIS 8.5时,不会给我任何错误,当我请求json结果时,总是给出“内部服务器错误500”。
这是代码。
控制器
[HttpGet]
public JsonResult TicketsAbertos(string username)
{
Computer computer = new Computer();
computer.GetHostDetails();
//return Json(JsonConvert.SerializeObject(result), JsonRequestBehavior.AllowGet);
string json = JsonConvert.SerializeObject(computer.GetOpenTickets(computer.User));
return Json(json, JsonRequestBehavior.AllowGet);
// return this.Json(computer.GetOpenTickets(computer.User), JsonRequestBehavior.AllowGet);
}
模型
public List<Computer> GetOpenTickets(string user_)
{
List<Computer> listar = new List<Computer>();
Dictionary<string, string> list = new Dictionary<string, string>();
//int result;
string connetionString = null;
SqlConnection cnn ;
connetionString = "Data Source=.\\HELPDESK;Initial Catalog=" + db + ";User ID=" + user_db + ";Password=" + pwd + "";
cnn = new SqlConnection(connetionString);
try
{
cnn.Open();
string query = "SELECT * FROM [tbl_user_details] JOIN [tbl_assistance_description] ON [tbl_user_details].username LIKE @user_ AND [tbl_assistance_description].Status LIKE @status_ ORDER BY [tbl_assistance_description].Date DESC";
try
{
SqlCommand command = new SqlCommand(query, cnn);
command.Parameters.AddWithValue("@status_", "Aberto");
command.Parameters.AddWithValue("@user_", user_);
try
{
SqlDataReader dataReader = command.ExecuteReader();
if (dataReader.HasRows)
{
while (dataReader.Read())
{
try
{
listar.Add(new Computer()
{
//ID = dataReader.IsDBNull(0) ? Convert.ToInt32(null) : dataReader.GetInt32(0),
User = dataReader.IsDBNull(1) ? null : dataReader.GetString(1),
Host = dataReader.IsDBNull(2) ? null : dataReader.GetString(2),
IP = dataReader.IsDBNull(3) ? null : dataReader.GetString(3),
Location = dataReader.IsDBNull(4) ? null : dataReader.GetString(4),
ID = dataReader.IsDBNull(6) ? 0 : dataReader.GetInt32(6),
Report = dataReader.IsDBNull(7) ? null : dataReader.GetString(7),
Description = dataReader.IsDBNull(8) ? null : dataReader.GetString(8),
Date = dataReader.GetDateTime(10).ToString(),
Status = dataReader.IsDBNull(11) ? null : dataReader.GetString(11)
});
}
catch (SqlException ex)
{
listar.Add(new Computer()
{
DB_RESULT = ex.Message
});
}
}
}
}
catch (SqlException ex)
{
listar.Add(new Computer()
{
DB_RESULT = ex.Message
});
}
cnn.Close();
}
catch (SqlException ex)
{
listar.Add(new Computer()
{
DB_RESULT = ex.Message
});
}
}
catch (SqlException ex)
{
listar.Add(new Computer()
{
DB_RESULT = ex.Message
});
}
return listar;
}
Ajax请求
$("#Aticketsabertos").live("click", function (evt) {
$(".featured .content-wrapper").slideUp();
$("#AdminMenu").hide();
var result = "";
$("#result").fadeOut();
evt.preventDefault();
$("#indexform").hide();
$("#Ticketsabertos").show();
$("#Ticketsfechados").hide();
$(".featured .content-wrapper").slideDown();
$.ajax({
type: "GET",
url: "helpdesk/Home/TicketsAbertos",
//data: { username: $("#User").val() },
//jsonp: false,
dataType: "json",
contentType: "application/json",
success: function (output) {
output = JSON.parse(output);
$("#result").show();
console.log(output);
$.each(output, function (i, item) {
if (item.DB_RESULT != "") {
result += item.DB_RESULT;
} else {
result += "<tr>" +
//"<th>User</th><td>" + item.User + "</td>" +
//"<th>Host</th><td>" + item.Host + "</td>" +
//"<th>IP</th><td>" + item.IP + "</td>" +
"<td>" + item.ID + "</td>" +
"<td>" + item.Report + "</td>"+
"<td>" + item.Description + "</td>" +
"<td>" + item.Location + "</td>" +
"<td>" + item.Date + "</td>" +
"<td class='statusaberto'>" + item.Status + "</td>" +
"</tr>"
;
};
}),
$("#result").removeClass().addClass("result_table").fadeIn().html("<table><tr>"+
"<th>ID</th><th>Tipo</th><th>Descrição</th><th>Local</th><th>Data</th><th>Status</th>" + result + "<table>");
},
error: function (xhr, textStatus, jqXHR) {
$("#result").fadeIn();
$("#result").removeClass().addClass("result_error").text("ERRO:" + xhr.status + " " + xhr.statusText + " " + DisplayError(xhr));
console.log(DisplayError(xhr));
}
});
return false;
});
响应标题始终是“text / html”,而不是json。 mime类型.json它被添加。