views:

173

answers:

1

Most of our projects are short term and of a promotional nature. As a result, our clients often want to put up some sort of "end of program" or "expired" page when the promotion is over. How do I do a blanket redirect of all controller actions to one specific controller action without modifying each controller and its methods? Is this even possible?

Ideally, in pseudocode, I'd like to be able to do something like this:

// somewhere in global.asax
if (current_action_url != desired_action_url)
    redirect to desired_action_url

I tried doing simple string matching on the URL:

if (!Request.Url.AbsolutePath.ToLower().EndsWith("path/to/desired/page"))
    Response.Redirect("path/to/desired/page");

However, since I'm still using IE 6 and have to use the wildcard hack, IE was redirecting all requests to the page (even images and stylesheets) which messes things up pretty badly.

A: 

How about using routes? Define routes that are for valid promos, the catch all can go to the generic "promo expired" page

        routes.MapRoute(
                "PromoStillGoing",
                "path/to/PromoStillGoing/{action}",
                new { controller = "PromoStillGoing", action = "Index" });

        routes.MapRoute("Catch All", "{*path}", new { controller = "ExpiredPromos", action = "Index" });

The above will do one page for all expired promos, not sure by your question if that is what you want.

If you want to have one expired page per promo, then in the routes you can "ignore" the action in the requested url like

        routes.MapRoute(
                "ExpiredPromoName",
                "path/to/PromoName/",
                new { controller = "PromoName", action = "Index" });

Now anything under /path/to/PromoName will use the Index action of the PromoNameController

jayrdub
I think the "{*path}" part was the missing piece. I'll try it tomorrow and give you the question if it works. Thanks!
Chris