Http 404 Page Not Found in Web API Hosted in Iis 7.5

HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

I was struggling with this as well. Fortunately, Steve Michelotti documented a solution that worked for me here.

At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>

Others have pointed out that having WebDAV enabled causes issues. Fortunately, I did not run into that issue as well.

ASP.NET Web API application gives 404 when deployed at IIS 7

While the marked answer gets it working, all you really need to add to the webconfig is:

    <handlers>
<!-- Your other remove tags-->
<remove name="UrlRoutingModule-4.0"/>
<!-- Your other add tags-->
<add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
</handlers>

Note that none of those have a particular order, though you want your removes before your adds.

The reason that we end up getting a 404 is because the Url Routing Module only kicks in for the root of the website in IIS. By adding the module to this application's config, we're having the module to run under this application's path (your subdirectory path), and the routing module kicks in.

WebAPI deployed to IIS, gives 404 Not Found

You host it on the application accessed by /api, so you need an additional /api to match the routing:

http://localhost:6060/api/api/Product

If you don't want that, then either give the api site a more sensible name, remove the api/ from the route, or both.

Why web API return 404 when deploy to IIS

There are a couple of issues that I can see here.

  1. The physical path should be set to D:\api_publish and not in the bin folder.
  2. Check the application pool is set to use .NET CLR Version v4.

As you mentioned in the comments, the default website already points to the same physical folder. You can either:

  1. Move the default website to another path.
  2. Use the default website instead of the serverapi one you created.

HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

I was struggling with this as well. Fortunately, Steve Michelotti documented a solution that worked for me here.

At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>

Others have pointed out that having WebDAV enabled causes issues. Fortunately, I did not run into that issue as well.

ASP.NET Web API on IIS7 - Not Found 404

I would make sure you are using the correct url/location when making the GET request, if your making the GET request off of your own project then it could change if you deploy to another location.

If you need a more specific answer please give some more details and code.

Error retrieving token ASP.NET Web API template iis 7.5 404 not found

After a couple of days thinking and trying. I found a solution that worked for me. In my previous code it worked only in iisexpress (I don't know why so if someone knows please share!). But in my new code it worked for both iisexpress and iis 7.5.

using ConsoleApplication1.Helpers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
const string userName = "user@user.com";
const string password = "Password01!";
const string apiBaseUri = "http://localhost/WebAPITest";

private static async void GetAPIToken()
{
string responseJson = await ResponseAsStringAsync(string.Format("{0}/token", apiBaseUri),
new[]
{
new KeyValuePair<string, string>("password", password),
new KeyValuePair<string, string>("username", userName),
new KeyValuePair<string, string>("grant_type", "password"),
});

var jObject = JObject.Parse(responseJson);
string token = jObject.GetValue("access_token").ToString();
}

public static async Task<string> ResponseAsStringAsync(string url, IEnumerable<KeyValuePair<string, string>> postData)
{
string responseString = string.Empty;

var uri = new Uri(url);

using (var client = new HttpClient())
using (var content = new FormUrlEncodedContent(postData))
{
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

HttpResponseMessage response = await client.PostAsync(uri, content);

responseString = await response.Content.ReadAsStringAsync();
}

return responseString;
}

static void Main(string[] args)
{
GetAPIToken();
Console.ReadKey();
}

}

}

I hope it helps someone else with the same problem.

ASP.NET Web API returns 404 for PUT only on some servers

Those IIS servers have web-dav module installed on them and i bet it is not needed and it was installed because the person installing ticked all boxes.

Just remove web-dav from iis.

Alternatively use web.config to remove web dav module:

<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
...


Related Topics



Leave a reply



Submit