0

I have looked in this site and seen some discussionsthe on error 404. But I can not find the same one as mine.

I have an application build with ASP.NET MVC 4. The url routing has not problem at all when I run in Visual Studio 2010. However when I published the application to Windows 2008 R2 Enterprise server named "MyCompany" under IIS7.5's Default Web Site as an application named "Test", the routing url misses the application name "Test". Thus causes the error 404.

The url is suppossed to be "http://MyCompany/Test/Home/Index?fileType=Fin". However it shows "http://MyCompany/Home/Index?fileType=Fin".

If I deploy the application to different port saying 8080, it works fine with "http://MyCompany:8080/Test/Home/Index?fileType=Fin".

Thanks in advance if anyone can help.

My route function is -

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

My WebServer configuration is -

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1048576000" />
      </requestFiltering>
    </security>
  </system.webServer>

Update:

Robert reminded me of the Javascript potential problem. He is right. After reviewed my codes again, I found the location of the problem. This function -

function OnChange(dropdown) {
    var myindex = dropdown.selectedIndex;
    top.location.href = "Home/Index?fileType=" + dropdown.options[myindex].value;
    return true;
}

should be -

function OnChange(dropdown) {
    var myindex = dropdown.selectedIndex;
    top.location.href = "@Url.Content("~/")" +  "Home/Index?fileType=" + dropdown.options[myindex].value;
    return true;
}
8
  • Are you sure Test is set up as an Application and not just a subdirectory? Commented Jun 13, 2013 at 2:48
  • @RobertMcKee, I am sure. It was created as a subdirectory first. And then I right clicked the folder and converted it to application. Thanks Commented Jun 13, 2013 at 3:17
  • Why do you have FDICFT in your "default" route. I don't see any rules you have set up that should work at all with /Home/Index Commented Jun 13, 2013 at 4:13
  • @RobertMcKee, Hi Robert, I have tried different ways since the original way does not work. The "FDICFT" was "Test". I tried to put the application name in route to see if it works. Now I have removed it. It does not work. Commented Jun 13, 2013 at 13:33
  • When you say it misses the application name, are you saying that things like @Html.Action doesn't generate the correct URL, or that when you actually type in the URL into the browser it doesn't work? Commented Jun 13, 2013 at 16:03

1 Answer 1

2

I'm going to go out on a limb, and say you've likely hard coded a URL in your javascript instead of using one of the URL building functions. There are a number of ways around that, but you need to verify that is the case first. We would need to see the Index view (or the offending javascript file) to see how you are building the URL to be able to determine what exactly is wrong.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Robert. Problem is fixed and the issue is updated with the solution. It is the Javascript problem! I had overlooked.
You might want to consider using top.location.href = "@Url.Action("Index","Home")" + "?fileType=" + dropdown.options[myindex].value instead. Even better yet, you might do "@Url.Action("Index","Home",new {fileType="{0}"})".replace("{0}",dropdown.options[myindex].value) or similar. Let the framework do the heavy lifting of generating the correct URL as much as possible. You'll find this handy, especially if you want to change URLs later, do SEO work like enforcing lowercase, etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.