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?

5
  • 2
    Possible duplicate of ASP.NET MVC Routes with "File Extensions" Commented Jan 23, 2017 at 17:04
  • The 404 errors from your testing, or from the 3rd party device? Commented Jan 23, 2017 at 17:22
  • REST client simulating the request that the device would send. Commented Jan 23, 2017 at 18:17
  • You have in route table "api/orders.asp" but there is no in example "api" so what url do you want? Commented Jan 23, 2017 at 18:42
  • Possible duplicate of Configuring Route to allow dot as extension? Commented Jan 23, 2017 at 18:57

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

It was the web.config changes that did it! Thank you @MegaTron
Glad to have been of help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.