點(diǎn)字符“” 在MVC Web API 2中進(jìn)行請(qǐng)求,例如api / people / STAFF.45287
在web.config文件中進(jìn)行以下設(shè)置應(yīng)該可以解決您的問(wèn)題:
<configuration> <system.webServer><modules runAllManagedModulesForAllRequests='true' />解決方法
我嘗試使用的URL是以下格式的URL:http ://somedomain.com/api/people/staff.33311(就像LAST.FM這樣的站點(diǎn)允許其RESTFul和WebPageurl中的各種符號(hào)一樣,例如“http://www.last.fm/artist/psy’aviah”是LAST.FM的有效網(wǎng)址)。
在以下情況下有效:-http://somedomain.com/api/people/-返回所有人-http://somedomain.com/api/people/staff33311-也可以使用,但不是我所需要的我希望網(wǎng)址接受一個(gè)“點(diǎn)”之后的m,例如下面的示例-http://somedomain.com/api/people/staff.33311-但這給了我一個(gè)
HTTP Error 404.0 - Not FoundThe resource you are looking for has been removed,had its name changed,or is temporarily unavailable.
我已經(jīng)設(shè)置了以下內(nèi)容:
控制器“ 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 });
}
我已經(jīng)嘗試按照該博客文章的所有提示進(jìn)行操作,網(wǎng)址為http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx,但仍然無(wú)法正常工作。更好,更安全的方式。
我們的ID在內(nèi)部是這樣的,因此我們將不得不找到一種解決方案,以一種或另一種方式來(lái)匹配點(diǎn),最好采用“”樣式。但如果需要的話,我愿意接受有關(guān)網(wǎng)址的替代建議…
