gpt4 book ai didi

javascript - Web API - 保留字?

转载 作者:行者123 更新时间:2023-12-02 15:29:27 25 4
gpt4 key购买 nike

**有一个非常简单的 Web API:

WebApiConfig.cs:

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional});

我可以通过我的数据服务 Controller 调用此 Web API:

[HttpGet]
public HttpResponseMessage GetUsers(string id)
{
var cl = _SecurityRepository.GetUsers(id);
return Request.CreateResponse(HttpStatusCode.OK, cl);
}

逻辑非常简单:在数据库中搜索以 id 中最后三个字母开头的任何姓氏

通话:

http://example.com/api/dataservice/Getusers/lop

结果:

[
{
"userID": "DLopez",
"firstName": "Don",
"lastName": "Lopez",
"department": "Information Technology"
},
{
"userID": "SLOPER",
"firstName": "Steve",
"lastName": "Loper",
"department": "First Services"
},
{
"userID": "DLOPES",
"firstName": "Davey",
"lastName": "Lopes",
"department": "Public Info"
}
]

一切都很好。是的!但是,在一种情况下,我通过此调用收到资源无法找到错误:

http://example.com/api/dataservice/Getusers/con

我可以使用 id=can、cone、com 等,...这些 api 调用都没有问题。他们都工作得很好。当我搜索 con -> 资源时找不到!有人有线索吗?我迷路了。

最佳答案

是的,“con”是保留字,不允许。解决方法是在 <system.web> 下包含以下内容在您的 Web.config 中。

<httpRuntime relaxedUrlToFileSystemMapping="true" />

取自 this answer .

关于javascript - Web API - 保留字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33445656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com