查了老半天,才發現是專案類型為ASP.NET MVC專案導致的,會將:
http://{site}/Foo.asmx/Bar這類的URL,以MVC的路由來處理,因為找不到對應的Controller,自然就得到404。
解決方法是在 RouteConfig.cs 新增 .asmx 檔的處理規則:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}