0
votes

I am trying to create Odata method that satisfy url like

domain:port/products/100/RedirectUrl()

[ODataRoute("{id}/RedirectUrl()")]
public IHttpActionResult RedirectUrl(int id)
{
   return Redirect("myUrl" + id);
}

but i got exception like

The path template '{id}/RedirectUrl()' on the action 'RedirectUrl' in controller 'Products' is not a valid OData path template

My Webapi config contains

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
builder.EntityType<Product>().Function("RedirectUrl").Returns<IHttpActionResult>();

Any way to achieve this?

1

1 Answers

0
votes

I think you want to enable Key as segment, track this https://github.com/OData/WebApi/pulls, then you can set the UrlConventions.ODataUrlConventions to enable it. Or you have to override the DefaultODataPathHandler to achieve this, may need to copy some private method like Parse.