asp.net mvc - MapRoute behaving differently depending on URI -
i have mvc pattern where, backwards compatibility of website migration, need support 2 specific .php files. 1 (mywebsite.com/afolder/select.php) behaves perfectly: controller called right action. other not (mywebsite.com/index.php). in latter case browser redirects (or gets redirected) mywebsite.com (default home controller, index method).
my 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 } ); }
my 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 controller too:
public class testttcontroller : controller { public actionresult foo() { return view(); } }
(setting breakpoint inside foo gets hit on /afolder/select.php not on /index.php)
it's index.php being in root rather subfolder makes behave differently. ideas why?
after going around in circles months (on , off) , last couple of days intensively, found way - still url rewriting not using web.config rules. ignore op - far simpler 2 .php page requests need handle. provided here such might useful someone.
handlers in web.config:
<add name="phphandler1" path="index.php" verb="get" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" /> <add name="phphandler2" path="foo/select.php" verb="get" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" />
global.asax.cs:
protected void application_beginrequest(object sender, eventargs e) { string fulloriginalpath = request.url.tostring(); if (fulloriginalpath.contains("index.php")) { context.rewritepath("/redirect/index"); } [...+select.php, etc...] }
simplified brevity, no error/exception handling shown. standard controller called redirecthandler index returning actionresult (or whatever).
Comments
Post a Comment