ASP.NET Web Api in Web forms

i´m trying to use the asp.net web api in WEB FORMS with visual studio 2010 (sp1)
i have done this steps http://myrandomykien.blogspot.com/2012/02/simplest-web-api-site-with-nuget.html

When i use the visual studio development server it works, but when i´m using iis 7.5 i get an Error HTTP 404.0 – Not Found.

Edit

This is my Global-asax

protected void Application_Start(object sender, EventArgs e)
        {
            RouteTable.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = System.Web.Http.RouteParameter.Optional }
            );
        }

This is the api class

public class GreetingController : ApiController
{
    public string GetGreeting(string id)
    {
        return String.Format("Hello {0}", id);
    }
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You have to make sure that extensionless requests are routed to ASP.NET which is done by default by your development server but not IIS.

There are couple of possible approaches.

First, you could add runAllManagedModulesForAllRequests="true" in the modules section of the system.webServer. Some people claim there are better methods, you can then follow them:

http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x