为了账号安全,请及时绑定邮箱和手机立即绑定

点字符'。' 在MVC Web API 2中请求诸如api / people / STAFF

点字符'。' 在MVC Web API 2中请求诸如api / people / STAFF

C#
慕容森 2019-08-17 15:34:05
点字符'。' 在MVC Web API 2中请求诸如api / people / STAFF.45287之类的请求我试图让工作的URL是以下风格的网址:http://somedomain.com/api/people/staff.33311(就像网站一样,LAST.FM允许在他们的RESTFul和WebPage网址中添加所有类型的标记例如,“ http://www.last.fm/artist/psy'aviah ”是LAST.FM的有效网址。以下方案有效: - http://somedomain.com/api/people/ - 返回所有人 - http://somedomain.com/api/people/staff33311 - 也可以,但不是我的意思在我希望网址接受“点”后,就像下面的示例 - http://somedomain.com/api/people/staff.33311 - 但这给了我一个HTTP Error 404.0 - Not FoundThe resource you are looking for has been removed, had its name changed, or is temporarily unavailable.我已经设置了以下内容:控制器“PeopleController”public IEnumerable<Person> GetAllPeople(){     return _people;}public IHttpActionResult GetPerson(string id){     var person = _people.FirstOrDefault(p => p.Id.ToLower().Equals(id.ToLower()));     if (person == null)         return NotFound();     return Ok(person);}WebApiConfig.cspublic static void Register(HttpConfiguration config){     // Web API configuration and services     // Web API routes     config.MapHttpAttributeRoutes();     config.Routes.MapHttpRoute(         name: "DefaultApi",         routeTemplate: "api/{controller}/{id}",         defaults: new { id = RouteParameter.Optional }     );}我已经尝试过这篇博文的所有提示http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx但它仍然无法工作..我也认为这很乏味,我想知道是否没有其他的,更好,更安全的方式。我们内部有这样的Id,所以我们必须找到一种解决方案,以这种或那种方式适合点,最好是“。”的风格。但如果需要,我愿意接受网址的其他建议......
查看完整描述

3 回答

?
梵蒂冈之花

TA贡献1900条经验 获得超5个赞

在您的web.config文件中进行以下设置后,应解决以下问

<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />


查看完整回答
反对 回复 2019-08-17
  • 3 回答
  • 0 关注
  • 492 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信