【发布时间】:2023-03-08 12:52:01
【问题描述】:
解决方案部署到 IIS 服务器时,Web API 端点未命中
工作端点: https://localhost:44335/Api/Course/GetStudents
端点不工作 http://192.168.1.3:9090/Api/Course/GetStudents
Ajax 代码
function GetStudents(IsEdit) {
$.ajax({
url: "/Api/Course/GetStudents",
type: "GET",
dataType: 'json',
success: function (data) {
$.each(data, function (i, obj) {
$('#ddlStudent').append($('<option>').text(obj.Student_Name).attr('value', obj.Student_Id));
});
if (IsEdit === true) {
$('#ddlStudent').val(SelectedSupplier).select2();
}
else {
GetCourses(false);
}
}
});
}
Web API 控制器
[HttpGet]
[Route("GetStudents")]
public string GetStudents()
{
string JsonString = String.Empty;
DBPROC dBPROC = new DBPROC(configuration);
DataTable Dt = dBPROC.GetDataTable("SP_GetStudents");
if (Dt.Rows.Count > 0)
{
JsonString = JsonConvert.SerializeObject(Dt);
}
return JsonString;
}
【问题讨论】:
-
请求的响应码是什么?这应该可以让您了解问题所在。
-
@Rory McCrossan 响应状态为 500
-
好的,所以它被击中了,但是有一个内部服务器错误?数据库连接是否正确,SP_GetStudents 是否存在?顺便说一句,作为旁注,你不应该在你的存储过程前加上 SP_
-
@Christain 存储过程存在代码在本地主机上工作正常并按预期返回 json 数据,在 IIS 上部署后无法正常工作
-
我想你可以使用 Try/catch 块,并将错误消息和堆栈跟踪作为字符串返回,至少你会知道什么是失败的。
标签: jquery ajax .net-core asp.net-core-webapi