How to trick a page into running at a location different from it'sphysical location?

Discussion in 'ASP .Net' started by Luke Dalessandro, Jan 15, 2006.

  1. I have an application with a web page that I would like to run as if it
    were at a different location than it actually resides at. As an example:

    Imagine that I have a site layout as,

    ~/
    ~/foo/
    ~/foo/bar/

    Web.config files exist at

    ~/web.config
    ~/foo/web.config
    ~/foo/bar/web.config

    I have a web page

    ~/default.aspx

    If someone comes along an requests page

    ~/foo/bar/default.aspx

    I would like the request to be handled by ~/default.aspx, but as if it
    were located at ~/foo/bar/default.aspx, importantly, I want all of the
    inherited web.config information to reflect the ~/foo/bar/ path
    hierarchy. I also want page-relative links to resolve based at ~/foo/bar.

    I can't rewrite the path via RewritePath because the framework executes
    ~/default.aspx as if it is at ~/default.aspx, and I can't redirect the
    client or server.transfer for the same reason.

    I have written a custom IHttpHandlerFactory that handles determining the
    correct page to load for each request (not precisely url rewriting but
    similar), but I can't figure out how to get the page to load as if it is
    at the requested url.

    Essentially, my factory looks like this:

    string newPath = DetermineNewPathForRequest(context);
    return PageParser.GetCompiledPageInstance(newPath,
    HostingEnvironment.MapPath(newPath), context);

    This almost works. Page relative links resolve correctly, and custom
    configuration sections that I've written respond to
    WebConfigurationManager.GetSection calls correctly, but built-on
    configuration sections don't get the inherited data.

    For instance, if I define

    ~/web.config <- <pages masterPageFile="default" theme="default" />
    ~/foo/web.config <- <pages masterPageFile="foo" theme="foo" />
    ~/foo/bar/web.config <- <pages masterPageFile="bar" theme="bar" />

    requesting ~/default.aspx, ~/foo/default.aspx, or ~/foo/bar/default.aspx
    always returns a page with the default theme and master file, rather
    than default.aspx customized with the appropriate theme/master set by
    the execution directory's web.config, even though my factory doesn't
    redirect, just loads the page directly.

    This disparity between the automatic configuration sections and the
    custom sections returned from WebConfigurationManager.GetSection really
    confuses me. Does anyone know if I'm running into a bug, or is there
    something about PageParser.GetCompiledPageInstance that I don't understand.

    Thanks in advance, and sorry for the long post,
    Luke
     
    Luke Dalessandro, Jan 15, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page