Reputation: 1572
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;
}
Upvotes: 0
Views: 2433
Reputation: 21487
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.
Upvotes: 2