views:

33

answers:

2

We currently have a problem whereby on our stage servers, links that exist on certain pages have a full url instead of a relative path, for example they may be on http://stage.host.com/app/webpage1.aspx, and a link may exist to http://www.host.com/app/webpage2.aspx instead of http://stage.host.com/app/webpage2.aspx

To try and solve this problem we added a response filter to strip out the host name for anchor tags, so that they become relative. Although this works well for most situations, there are still some issues where users redirect to full links with server side code e.g. Response.Redirect.

I wanted to get your guys ideas about the best way to tackle this problem, I'm thinking maybe a HttpModule may help?

Thanks, Raj.

A: 

Usually, the hostname is configurable in the web application, or even automatically determined from the webserver environment.

Sjoerd
+1  A: 

If you are trying to limit any redirection to other hosts, you could use this:

public class Global : System.Web.HttpApplication
{
    //...

    protected void Application_EndRequest(object sender, EventArgs e)
    {
        if (this.Response.StatusCode == 302) this.Response.RedirectLocation = Relativize(this.Response.RedirectLocation);
    }

    //...
}

Or pretty much the same code in a HttpModule.

Jaroslav Jandek