asp.net - routing legacy webforms urls to mvc controller/actions? -
we planning convert legacy webforms incrementally on mvc. (and learning mvc along way!)
i wondering if routing appropriate way to, ineffect, replace old webforms pages controllers/actions 1 @ time. right have generated when creating mvc area , adding mvc project nuget:
public overrides sub registerarea(byval context arearegistrationcontext) context.maproute( "mvc_default", "mvc/{controller}/{action}/{id}", new {.action = "index", .id = urlparameter.optional} ) end sub
so controller "foo" action "bar", reference url ".../appname/mvc/foo/bar", while aspx pages accessed urls in ".../appname/pages/pagename".
can use additional maproute() calls above, or maybe mappageroute() in routeconfig.vb in app_start, map individual pages corresponding new mvc controller/action? like?
this let avoid touching messy code-behind on webforms side constructing our navigation urls.
if you're using iis, can have mvc routes masquerade webforms or classic asp urls using iis rewrite rules. don't have change legacy links may floating out there, , can keep old webforms pages around, , switch between mvc/webforms/classic asp (without redeploying site) toggling rewrite rules.
you can choose between redirect or rewrite, depending on whether or not want client see new mvc url.
here's example of classic asp -> mvc rewrite rule in web.config:
<rule name="apppagerewrite" enabled="true" stopprocessing="true"> <match url="app.asp" /> <action type="rewrite" url="/app" appendquerystring="true" /> </rule>
by way, converting web forms/classic asp site incrementally mvc (on per page, or sub-page level) has proven effective in experience (works in agile/scrum environment).
Comments
Post a Comment