简体   繁体   中英

Not found resource in controller web api Uri with .json

I need to run a REST query request to a Web API controller using the following format:

http://path/name.json?foo.bar.text=aCertainValue

(I cannot change this format since it depends on external providers).

The problem I have is that I cannot retrieve the query result.

I have tried the following options on my server code (written in C#):

[HttpGet]
[Route(Name = "name.json")]
public List<SpaceFound3rdParty> findRes([FromUri (Name = "foo.bar.text")] string text)
{...}

and

[HttpGet]
[Route("name.json")]
public List<SpaceFound3rdParty> findRes([FromUri (Name = "foo.bar.text")] string text)
{...}

none of which have succeeded.

If I specify a name without dots (ie a name without a path), and I use /? as separator between path name and resource name, I can retrieve the resource successfully. However, this is not an option (I have to use ? even though there is a single resource in the request.

How can I modify the C# server to retrieve the resource while maintaining the requested format pathName?resourceName ?

Paste your RouteConfig.cs here. You are using attribute routing so you might need to register those actions by calling this helper function, ' MvcAttributeRoutes() ' from RouteConfig.cs file.

Hope it solves!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM