tags:

views:

306

answers:

1

What's the difference in using the IIS Redirect module to redirect vs. just coding your own and playing with the Response.context? To me it doesn't make a difference, they both do the same thing and it's much easier to just use the redirect module in IIS as it appears to redirect relatively anyway! Same as this code is doing in lets say a global.asax:

app.Response.Status = "301 Moved Permanently"; app.Response.AddHeader("Location", newLocation);

Am I not right? you can do the same thing 2 different ways! IIS or code! Using IIS just puts this into your app's web.config:

<httpRedirect enabled="false" destination="http://www.domainToRedirectTo.com/" exactDestination="false" httpResponseStatus="Permanent" />

nice and simple! exactDestination is false, so it will redirect relatively based off of the destination.

I want to hear arguments against using one way vs. the other because I don't see an argument that benefits either way. The both satisfy the same goal.

+1  A: 

There is no difference in the way you have put it. A coded version allows you to react on input at runtime and use the code to redirect people to different pages --e.g., for a login.aspx page this might be a redirect to login-failed-page.aspx or login-succesfull-page.aspx. If its just hard-coded there is no difference.

Remember that redirects are not just meant to indicate permanent relocation of URL's. 301 is just one of the redirects. You may want to redirect people to a temporary message (redirect code 307) -- e.g., if you are working for apple and Steve Jobs is giving a keynote -- i.e., redirecting the store to a "Steve Jobs is giving a keynote and we are updating the store" page. In this example its far better to flick a switch and have your entire web-farm pick up the change via runtime logic than having to update the config files of all your IIS servers. Each redirect has its own purpose.

Hassan Syed
thanks, well in this case we want 301 redirects 100% of the time for this application as it was moved to a new domain.
CoffeeAddict
I get the config.update issue, but either way, you're going to have to remove or change code. Whether it is in the config <httpRedirect> or in a handler class or in the global.asax, you're goign to have to deal with it somehow through code. Wouldn't it be much easier through the web.config, a central piont for something like this rather than a class? I guess it depends on your deployment..yes you're copying up the assembly and don't need to deal wtih the web.config but I guess to me it's just 2 ways to "manage" this setting and this redirect.
CoffeeAddict
very interesting about the web farm scenario....we have that but I don't see why it's a big deal just to configure this via web.config and check it into source control and deploy the web.config!
CoffeeAddict
Changing servers individually is expensive (try thinking about a 1000 servers); also, the example I give is business policy related, and the HTTP redirect is a general mechanism to implement many different aspects.
Hassan Syed