neriag
neriag

Reputation: 151

Publishing application to IIS: Web API breaks

I have built a Asp.Net MVC application, and it's worked successfully. However, when I published it to IIS I can't access the web service. I mean, when I enter some url of content (for example "http://localhost/MyApp/Contents/SomePage.html") it's works successfully, but when I enter url of the api ("http://localhost/MyApp/api/SomeController/SomeMethode") I get 404.2 error. [When I Entered such url when it was unpublish,("http://localhost:5092/api/SomeController/SomeMethode") it's showed me the result of the method]

Thanks a lot, and sorry for the bad english.

UPDATE Thanks for the answers, I tried both of them (in the comment and in the answer) and It's didn't work. Actually, I tried to solve it 4 hours and I just couldn't. So like every angry guy I removed the publish and published it again (Just like restarting the computer when it's stuck) and I don't know why, but now it's works.

Thanks again, and sorry again for the bad English.

Upvotes: 0

Views: 110

Answers (1)

sjokkogutten
sjokkogutten

Reputation: 2095

MVC routing is different from WebApi routing.

MVC:

RouteTable.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "{controller}/{id}",
      defaults: new { id = System.Web.Http.RouteParameter.Optional }
 );

WebApi

GlobalConfiguration.Configuration.Routes.MapHttpRoute(
     name: "DefaultApi",
     routeTemplate: "api/{controller}/{id}",
     defaults: new { id = System.Web.Http.RouteParameter.Optional }
   );

In your Global.asax

protected void Application_Start()
{
    GlobalConfiguration.Configure(WebApiConfig.Register);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
}

Upvotes: 0

Related Questions