views:

72

answers:

2

I would like to mark some pages in my site that is currently in the wild as "obsolete" and pick up on that in my global.asax and redirect the client to a different page.

Then I will have the site notify the dev team that someone tried to hit that page.

Can you access the Type information for the page from any global place?

+2  A: 

Provided that you have the following page:

[Obsolete]
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { }
}

In global.asax you could do this:

protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    if (!(this.Context.Handler is System.Web.UI.Page))
    {
        return;
    }

    var isPageObsolete = this.Context.Handler
            .GetType()
            .BaseType
            .GetCustomAttributes(typeof(ObsoleteAttribute), true)
            .Length > 0;
    if (isPageObsolete)
    {
        Response.Redirect("http://www.google.com");
    }
}
Darin Dimitrov
simple, elegant, nice.Didn't know that the "handler" was the page. Thanks Darin.
DevelopingChris
A: 

I think Darin's answer is quite creative. I'm offering another perspective. The method discussed so far is marking the page AT the page. How about marking the page say in the config or another xml file like this.

<obsoletePages>
  <page path="/page123.aspx />
  <page path="/pagexyz.aspx />
</obsoletePages>

At global.asax, intercept the request at Application_BeginRequest(), if the request page is found within the configuration file, perform the redirect.

o.k.w
I had explored this route personally, as the easier solution to implement. The hard part is, its hard to know, when you are trying to get a page to run, why the hell you are getting redirected. Making maintenance on the obsolete's more confusion. My thought is to also mark a date when something was obsoleted and before every release to go find the things that have been obsolete in production fro 90 days or whatever and prune them.
DevelopingChris
Managing individual pages' state of obsolete, isn't that more tedious than managing from a single point. Anyway, you should know better as you understand the nature of your app and development protocol. Good luck!
o.k.w