Fiddler
Fiddler

Reputation: 53

WebAPI displays 404 error when deploying on Server using IIS 7 but works fine as selfhost

Any help would be greatly appreciated. I have been researching this problem for a couple days now. here is what's happening.

I created my first WebApi service in vs 2012 using the templete under mvc4. I have kept most of the default settings. I did change the router in WebApiConfig.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace GetBalanceSV
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "SubscriberActivity/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

I can run this fine in debug mode on my machine. I published on my machine through VS2012 and ran it as a self host using IIS and can call the get method and get a response back with no problems. using

"http://localhost/SubscriberActivity/Values/Testingingmystring"

I can also deploy this on our web development server with IIS as a new web site in a self host and will run fine on the server that way. BUT when i put under a existing web site using the same Application Pool it fails. 404 error.

I ran this through fiddler2 and this was the response i got.

*HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 07 Oct 2013 17:04:59 GMT
Content-Length: 1937
<!DOCTYPE html>
<html>
    <head>
        <title>The resource cannot be found.</title>
        <meta name="viewport" content="width=device-width" />
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
         @media screen and (max-width: 639px) {
          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
         }
         @media screen and (max-width: 479px) {
          pre { width: 280px; }
         }
        </style>
    </head>
    <body bgcolor="white">
            <span><H1>Server Error in '/SubscriberActivity' Application.<hr width=100% size=1 color=silver></H1>
            <h2> <i>The resource cannot be found.</i> </h2></span>
            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
            <b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. &nbsp;Please review the following URL and make sure that it is spelled correctly.
            <br><br>
            <b> Requested URL: </b>/SubscriberActivity/values/testeing<br><br>
    </body>
</html>*

Does anyone have any idea why this might be happening?

Upvotes: 3

Views: 3774

Answers (2)

Sadish Kumar V
Sadish Kumar V

Reputation: 106

Check whether Existing App Pool is in Classic or Integrated Mode. If it is Classic Mode then change it to Integrated Mode

Upvotes: 1

A Khudairy
A Khudairy

Reputation: 1492

Am not exactly sure what you mean by "BUT when i put under a existing web site using the same Application Pool it fails." ... but on any way, i believe your issue is in:

  • maybe the iis needs an update to support extensionless urls (unless it already worked fine being hosted on same iis that would mean it already support it). check this

  • Make sure that your http handlers are correct (look at section in web.config in visual studio, and make sure the deployed version has the same http handlers). As am afraid you are deploying the wrong way.

you might also check this link

Upvotes: 0

Related Questions