我制作了MVC4 App。我写这个是为了自动完成。
$(document).ready(function () {
$("#Search_PartNumber").autocomplete({
source: function (req, resp) {
$.ajax({
type: "GET",
url: '@VirtualPathUtility.ToAbsolute("~/AjaxService/AutoCompleteService.svc/GetPartNumberListModel")',
cache: false,
dataType: "json",
data: { param1: req.term },
success: function (o) { resp(o.d); },
error: function (xhr, ts, err) { resp(['']); }
});
}
});
});
AjaxService 是文件夹名称。 forder 包括两个文件 AutoCompleteService.svc 和 AutoCompleteService.svc.cs。AutoCompleteService.svc 包含一个方法 GetpartNumberListModel,它适用于 sql 选择。
源。
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
public string[] GetPartNumberListModel(string param1)
{
.....
return list.ToArray();
}
我的问题,它在可视化工作室中成功运行。但在 IIS 服务器中不起作用。据说找不到"GetPartNumberListModel"。
我测试了是否可以在网络浏览器上访问该地址。如果我在我的开发 PC 中访问"http://localhost:80/AjaxService/AutoCompleteService.svc/GetPartNumberListModel"。我可以得到json文件。但是,如果我在 IIS 服务器中访问例如"http://150:120:110:111:8080/AjaxService/AutoCompleteService.svc/GetPartNumberListModel"。我只找不到 404 错误。但是"http://150:120:110:111:8080/AjaxService/AutoCompleteService.svc"是成功的。
如果您知道,请给出一些想法。如果您需要更多信息或无法忍受我的英语。只是评论我。谢谢!
我用这种方式很确定。
我需要使用 Windows 身份验证。所以我将Windows身份验证设置为站点的所有文件夹。并设置匿名身份验证仅AjaxService文件夹。