我有一個MVC模式,爲了向後兼容網站遷移,我需要支持兩個特定的.php文件。其中一個(mywebsite.com/aFolder/select.php)表現完美:使用正確的操作調用控制器。其他不(mywebsite.com/index.php)。在後一種情況下,瀏覽器只是重定向(或重定向)mywebsite.com(默認主控制器,索引方法)。MapRoute根據URI行爲有所不同
我RouteConfig.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "php2",
url: "aFolder/select.php",
defaults: new { controller = "Testtt", action = "Foo" }
);
routes.MapRoute(
name: "php1",
url: "index.php",
defaults: new { controller = "Testtt", action = "Foo" }
);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
我的web.config:
<system.webServer>
<handlers>
<add name="PhpHandler1" path="index.php" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="PhpHandler2" path="aFolder/select.php" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
FWIW控制器太:
public class TestttController : Controller
{
public ActionResult Foo()
{
return View();
}
}
(設置裏面美孚斷點被擊中的/ aFolder/select.php但不在/index.php上)
這是關於index.php是在根,而不是一個子文件夾,使其行爲有所不同。任何想法爲什麼?
我在URL重寫方面取得了有限的成功,但仍然遇到令人沮喪的異常。只要原始URL及其參數仍然可用,重寫到/ MyController/MyAction會很好。 – GeoffM