您的位置:首頁技術文章
文章詳情頁

點字符“” 在MVC Web API 2中進行請求,例如api / people / STAFF.45287

瀏覽:96日期:2024-05-11 16:58:42
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決點字符“” 在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在內部是這樣的,因此我們將不得不找到一種解決方案,以一種或另一種方式來匹配點,最好采用“”樣式。但如果需要的話,我愿意接受有關網址的替代建議…

標簽: web
国产综合久久一区二区三区