tags:

views:

181

answers:

2

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 module? Or is there any easier way to do this using .Net 2.0 & IIS6?

+1  A: 

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

SLaks
+1  A: 

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.

Luhmann