1

EDIT: The 'duplicates' are not working - not sure why exactly.

I need to be able to support an ASP.NET WebApi (v5.2.3.0) route that looks like this:

https://example.com/orders/orders.asp

It's for a 3rd party device to be able to interact with my system. I've tried messing around with the RouteConfig like this:

routes.MapHttpRoute(
            name: "Orders",
            routeTemplate: "api/orders.asp",
            defaults: new { controller = "OrderConfirm", action = "Get", id = RouteParameter.Optional }
        );

But I always get a 404 error. I've messed around with the "Route" decoration, like this:

[Route("api/orders.asp")]

Controller code:

public class OrdersConfirmController : ApiController
{
    [HttpGet]
    public HttpResponseMessage Get()
    {
        string orderContent = "blah, blah, blah";
        var response = Request.CreateResponse(HttpStatusCode.OK, string.Empty);
        response.Content = new StringContent(orderContent, Encoding.UTF8, "text/plain");
        return response;
    }
}

But still the 404 errors.

Ideas?

coach_rob
  • 877
  • 13
  • 28
  • 2
    Possible duplicate of [ASP.NET MVC Routes with "File Extensions"](http://stackoverflow.com/questions/255876/asp-net-mvc-routes-with-file-extensions) – bolt19 Jan 23 '17 at 17:04
  • The 404 errors from your testing, or from the 3rd party device? – Brian Mains Jan 23 '17 at 17:22
  • REST client simulating the request that the device would send. – coach_rob Jan 23 '17 at 18:17
  • You have in route table "api/orders.asp" but there is no in example "api" so what url do you want? – Roman Marusyk Jan 23 '17 at 18:42
  • Possible duplicate of [Configuring Route to allow dot as extension?](http://stackoverflow.com/questions/40561302/configuring-route-to-allow-dot-as-extension) – Nkosi Jan 23 '17 at 18:57

1 Answers1

1

Add a new route at the top of route table

config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
      name: "Orders",
      routeTemplate: "{controller}/{action}.asp"
);
config.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new { id = RouteParameter.Optional }
);

To OrdersConfirmController add attribute:

[RoutePrefix("Orders")]
public class OrdersConfirmController : ApiController

and for action

[Route("orders.asp")]
[HttpGet]
public HttpResponseMessage Get()

Also to allow dot in URL you need to add this to web.config

<system.webserver>
    <modules runAllManagedModulesForAllRequests="true">

Now you can reach resourse by http://example.com/Orders/orders.asp

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116