Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Unassigned: Web Api 2 Attribute Routing - Extension Issue [1203]

$
0
0
I am using the new attribute routing in Web Api 2 and am having the following issue with web hosting

I have set up extension mapping as follows:

```
config.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "text/html");
config.Formatters.JsonFormatter.AddUriPathExtensionMapping("json", "application/json");

```
and have the following action:

```
[HttpGet("pets")]
[HttpGet("pets.{ext}")]
public HttpResponseMessage Get()
{
......
}
```

A GET request to /pets is successful, however a GET request to /pets.json results in a 404.

If I change the action to the following

```
[HttpGet("pets")]
[HttpGet("pets/{ext}")]
public HttpResponseMessage Get()
{
......
}
```

Then a GET request to /pets/json results in the content returning as JSON which is what I was expecting a GET to /pets.json to do.

This scenario was working using the existing attribute routing library in web api 1

Is there is an issue having a period in the route ?
Comments: Yeah, right...In web-hosted scenario , you would need to have the following setting in Web.config to make the requests having period succeed: ``` <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> ``` This is true both for attribute and non-attribute(conventional) based routing mechanisms. Regarding your comment about it working in existing attribute routing library in web api 1, I believe you meant the "AttributeRouting.WebApi" package from Tim McCall..right? if yes, this problem occurs even with that package too and you would need the above setting in web.config to make the requests succeed.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>