Web API endpoint without resourceAsk Questions

 Posted on 13/07/2018 11:49:23 AM

I want my webapi endpoint to have a Get action without resource.

Ex: http://localhost:56155/ Resource: api/program/get, this action I want to hit when someone hit

http://localhost:56155/ in the browser. Is that possible?

I added this in webapiconfig.cs

     name: "DefaultApi", 
     routeTemplate: "api/{controller}/{action}/{id}", 
     defaults: new { controller = "Program", 
                     action = "Get", 
                     id = RouteParameter.Optional 
But it does not redirect or hit the action Get of my Program controller when I launch the app.
Share On: facebook gplus twitter
Asked by ketan Linbachiya on 13/07/2018 11:49:23 AM Score: 269 points
Add Comment:


1 Answer

0 Corrected Answers
Answered by Hardik Bera on Aug 16 2018 3:50PM Score: 375 points

You have mandatory segment api in your routeTemplate routeTemplate: "api/{controller}/{action}/{id}".

Just remove this segment and the route will work with the empty url routeTemplate: "{controller}/{action}/{id}".

i hope this helps

Add Comment:

Post Your Answer


Existing Members

Sign in to your account
Email Address
...or Join us
Download, Vote, Comment, Publish.
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.