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?
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
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.