Keeping users on the same host, development environment
We currently have a problem whereby on our stage s开发者_StackOverflowervers, 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.
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
.
Usually, the hostname is configurable in the web application, or even automatically determined from the webserver environment.
精彩评论