1

The following is WORKING on my test web server (IIS 7 on Windows 7):

enter image description here

But the exact same code gives me the following 404 error on both production web servers:
(IIS 7 on Windows Server 2008 AND IIS 6 on Windows Server 2003)

enter image description here

[The Code]

Global.asax routing setup:

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

Page.aspx jQuery statement:

    $.ajax(
    {
        url: "api/Department/" + '<%= Request.QueryString["deptId"] %>',
        contentType: "application/json",
        dataType: "json",
        success: function (data) {
            alert('hello');
        }
    });

DepartmentController.cs GET method:

[HttpGet]
public Department GetDepartment(int deptId)
{
    var deptRepo = new DepartmentRepository();
    return deptRepo.GetDepartment(deptId);
}

I browsed a lot of similar questions on here but didn't find an answer to this.
Why would the same code work on one web server but not on others?
Is there something special I need to configure in my application or IIS?
I am really stuck on this. Any help would be greatly appreciated.

Baxter
  • 5,633
  • 24
  • 69
  • 105
  • Might sound dumb, but we gotta check...looks like you're browsing to the httpS version of this url. Does it still 404 if you go to the regular http similar to your test web server screenshot? – ethorn10 Sep 26 '13 at 03:01
  • @ethorn10 Thank you for your comment. I can't navigate to http on the production web servers. However, I have another test web server and the code also fails on http. If https was the issue what might I do to resolve that? – Baxter Sep 26 '13 at 03:12
  • I doubt https is your problem. Typically routes have an `action` defined in them somewhere and I don't see one for you, so I'm not really sure how that even works locally...perhaps a Web API thing that I'm not aware of yet. – ethorn10 Sep 26 '13 at 10:31

2 Answers2

2

Not sure if you are still having issues with this. I was able to resolve this issue by adding this to my web.config on the IIS Server. This coming from here. The original answer was found from here

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>

Community
  • 1
  • 1
James
  • 21
  • 4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – godel9 Dec 12 '13 at 16:03
  • First time answering on stackoverflow. Thank you for the advice. Added the essentials to the resolution from the linked answer so if the link breaks the answer still exists. – James Dec 12 '13 at 17:41
  • Thank you. People who find your answer in the future will definitely appreciate it. :-) – godel9 Dec 12 '13 at 19:41
1

This is a bit late for an answer, but I think this might help others in a similar situation.

Adding another routing rule to your RouteTable should clear out this not found error. This routing rule should start with the first folder name mentioned in your production server path i.e. start with forms and not api when mentioning the second rule. Let the original rule be there since you can have multiple rules in RouteTable. Also, don't change the path in the jQuery you were using originally because 'forms' will be automatically appended when using 'api/...' in the jQuery url.

Make sure you do not give the name of 'DefaultApi' to this new rule since there is already a rule by the name of 'DefaultApi' that will result in compile-time error.

RouteTable.Routes.MapHttpRoute(
    name: "Rule1Api",
    routeTemplate: "forms/api/{controller}/{deptId}/{member}",
    defaults: new { deptId = RouteParameter.Optional, member = RouteParameter.Optional}           
    );
Sunil
  • 20,653
  • 28
  • 112
  • 197