locked
Redirect logic only when physical page not found RRS feed

  • Question

  • User-35046230 posted

    I am building some URL logic that will go into an Http Module. The logic is somewhat expensive (includes a database lookup) and maps virtual URL's to the appropriate physical page.

    I want to be sure that the logic isn't called if the request is for a physical page (the logic only applies to virtual URL's). How/where do I plug into the .aspx pipeline to ensure that my logic is only invoked if the request is not for a physical page?

    Thanks.

    Mark

    Sunday, May 24, 2009 1:20 PM

Answers

  • User-1136466523 posted

    Hi,

    From your description, it seems that you want to active the database lookup logic only when you are requesting for a virtual url, right?

    I'm not sure what your httpModule looks like, generally, you can add your custom logic to identity if the current request is virtual or physical according to your rules. For samples:

     public void Init(HttpApplication context)
           
    {
                context
    .BeginRequest += new EventHandler(context_BeginRequest);
           
    }

           
    void context_BeginRequest(object sender, EventArgs e)
           
    {
               
    HttpContext context = HttpContext.Current;
               
    HttpRequest request = context.Request;

               
    if (request.Url.PathAndQuery.Contains("YourLogichere"))
               
    {
                    //........ 

                }
           
    }

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 26, 2009 10:37 PM

All replies

  • User-1136466523 posted

    Hi,

    From your description, it seems that you want to active the database lookup logic only when you are requesting for a virtual url, right?

    I'm not sure what your httpModule looks like, generally, you can add your custom logic to identity if the current request is virtual or physical according to your rules. For samples:

     public void Init(HttpApplication context)
           
    {
                context
    .BeginRequest += new EventHandler(context_BeginRequest);
           
    }

           
    void context_BeginRequest(object sender, EventArgs e)
           
    {
               
    HttpContext context = HttpContext.Current;
               
    HttpRequest request = context.Request;

               
    if (request.Url.PathAndQuery.Contains("YourLogichere"))
               
    {
                    //........ 

                }
           
    }

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 26, 2009 10:37 PM
  • User-35046230 posted

    Thank you for your response, Michael. I may not have explained my problem very well.

    I have a number of URL's that need to be mapped to physical pages. For example, let's say I have /products/category/toys as the URL that will be linked on various pages. When the request comes in I want to map that to, say, /productspage.aspx?category=toys. Let's imagine that I have a whole bunch of these virtual -> physical mapping to do and that in some cases the mapping requires a lookup in a database. This lookup is expensive so I want to only invoke that logic when the incoming URL is NOT for an existing virtual page. Thus, if a request comes in for /contact-us.aspx and that page is a real, live physical page, I want to bypass the aforementioned lookup logic.

    Basically, I want to implement logic that bypasses my virtual page logic when the incoming page does not resolve to a physical page. I am afraid I don't really follow your suggestion since it seems to imply there is something specific in the name of the URL (the contains() method) that I can use. This won't be the case. The trigger for my lookup code is whether the incoming request is for a physical page or not and does not have any relationship to the contents of the URL itself.

    Make sense?

    Thanks again.

    Mark

     

    Wednesday, May 27, 2009 11:11 AM