开发者

ASP.Net - Redirect any request to another domain of the same path

I'm going to be in a situation where I'll have www.DomainA.com and www.DomainB.com, each having seperate IPs. All requests to www.DomainB.com/{Path}, I'd like to redirect to www.DomainA.com/{Path}.

My initial reaction was, in the base directory, to simply create a HTTPModule and Web.config to add in the module, where the module would then redirect the request to DomainA. The only problem with this is IIS is not executing the module, and instead determining itself whether or not there is a matching file or application to run based upon the requested path (i.e. so you'll either get an error about the requested file not existing, or a security error about not finding the requested application).

What do I need to change in IIS to always run my mod开发者_如何学Cule? Or is there any easier way to do this using .Net 2.0 & IIS6?


Just do a simple app, and then in you Global.asax Application_BeginRequest put the code to redirect - something like:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    Dim strPath As String = HttpContext.Current.Request.Url.PathAndQuery
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.Status = "301 Moved Permanently"
    HttpContext.Current.Response.StatusCode = 301
    HttpContext.Current.Response.AddHeader("Location", "www.DomainA.com" & strPath)
End Sub

Remember the 301 status code to make the search-engines happy, by letting them know that its a permanent redirect.


Follow these instructions to force IIS to send all requests through ASP.Net.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜