点字符“” 在MVC Web API 2中进行请求,例如api / people / STAFF.45287
在web.config文件中进行以下设置应该可以解决您的问题:
<configuration> <system.webServer><modules runAllManagedModulesForAllRequests='true' />解决方法
我尝试使用的URL是以下格式的URL:http ://somedomain.com/api/people/staff.33311(就像LAST.FM这样的站点允许其RESTFul和WebPageurl中的各种符号一样,例如“http://www.last.fm/artist/psy’aviah”是LAST.FM的有效网址)。
在以下情况下有效:-http://somedomain.com/api/people/-返回所有人-http://somedomain.com/api/people/staff33311-也可以使用,但不是我所需要的我希望网址接受一个“点”之后的m,例如下面的示例-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.cs
public static void Register(HttpConfiguration config)
{ // Web API configuration and services
// Web API routesconfig.MapHttpAttributeRoutes();config.Routes.MapHttpRoute( name: 'DefaultApi',routeTemplate: 'api/{controller}/{id}',defaults: new { id = RouteParameter.Optional });
}
我已经尝试按照该博客文章的所有提示进行操作,网址为http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx,但仍然无法正常工作。更好,更安全的方式。
我们的ID在内部是这样的,因此我们将不得不找到一种解决方案,以一种或另一种方式来匹配点,最好采用“”样式。但如果需要的话,我愿意接受有关网址的替代建议…
