asp.net - Error in running web api -
i have asp.net web api project in there 1 api controller , within 1 method,nothing else.when seek run it,it showing below error
http error 403.14 - forbidden web server configured not list contents of directory. [cacheoutput(clienttimespan = 300, servertimespan = 300)] public ienumerable<movie> get() { homecoming repository.getemployees().orderby(c => c.empid); } and url http://domain:53538/api/employees
and webapiconfig is
public static void register(httpconfiguration config) { // web api configuration , services // web api routes config.maphttpattributeroutes(); config.routes.maphttproute( name: "searchapi", routetemplate: "api/{controller}/{action}/{searchstr}" ); config.routes.maphttproute( name: "defaultapiwithempid", routetemplate: "api/{controller}/{empid}", defaults: new { employeeid = routeparameter.optional } ); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); }
in code , can see next corresponds same routing url.
config.routes.maphttproute( name: "defaultapiwithmovieid", routetemplate: "api/{controller}/{movieid}", defaults: new { movieid = routeparameter.optional } ); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); note: in both cases lastly param marked optional, route left api/{controller} , when used api/movies, routing scheme got confused , stopped working!
so need re-arrange routing url, suggest replace 1st 1 ( in reply this)
config.routes.maphttproute( name: "defaultapiwithmovieid", routetemplate: "api/{controller}/{movieid}" ); so create movieid param mandatory, have url /api/movies/2 , here 2 film id
and later correspond api/movies( id here optional - referring 2nd code block in answer) , solution work,
asp.net asp.net-mvc iis asp.net-web-api web-api
No comments:
Post a Comment