Last post Dec 19, 2005 07:02 PM by StrongTypes
Dec 12, 2005 06:02 PM|Codepic|LINK
Just a quick (and still theoretical) question, if I wanted to return HTTP 200 and some page, when a user requests an non-existent URL on my domain, for example through an outdated link, is it possible with IIS / DNN?
I know I can craft an custom 404 page and then redirect user but I do not want to return http 404 + 302, instead I want to return the "redirected" content with http 200 OK
Can be done? How? Any Ideas?
Dec 15, 2005 11:04 PM|StrongTypes|LINK
In IIS you can define that all 404 errors are redirected to a certain page on your site. You will also need to define this in web.config for error 404 as web.config will override that setting for all ASP.NET pages. On the page you redirect to, you can handle
the event(s) that you wish to occur. I'd handle your logging / redirecting of URLs in the web form, but have it communicate with a database that stores broken requests as well as redirects for those broken links. Then create a utility for viewing the statistics
of the database as well as managing it's contents.
Below is a link to an example of code that could handle the broken requests:
Dec 18, 2005 03:06 PM|Codepic|LINK
Ah, but this would only work for ASP.NET pages. However I'd want to do this on any 404.
Wonder if ISAPI Rewrite would help in this matter as all I want to do, is return 200 and dynamic content instead of 404 and error page.
Dec 19, 2005 09:29 AM|dstgroup|LINK
Dec 19, 2005 11:19 AM|StrongTypes|LINK
The example I just showed you will be in use soon on a very heavily visited server and is already deployed on another heavily visited site, so I guarantee you it is not "a very slippery slope." That example works on ASP.NET pages as long as you set customErrors
to off in web.config and add a setting to forward all 404 requests to the not found handler in IIS.
<error statusCode="404" redirect="/404.aspx" />
Dec 19, 2005 12:53 PM|Codepic|LINK
Not only that, you would be breaking the proper way of handling broken links.
Thanks for the reply, but let's dwell on the above a bit. I guess in the early days of internet, it was very important to return 404 when one was met. Those days, most of the pages were static. But these days, it doesn't serve anyones purpose to actually
return a 404. Rather than that, one should probably return content. For example, for a hotlinked image one might return an image with text "sorry, but the image you were looking for is relocated. You might try to find it here: http://www.thisdomain.com/imagesearch.aspx".
More than that, the DNN doesn't properly answer 404 when file doesn't exist. For example
http://www.thisdomain.com/Home/tabid/35/Default.aspx Has anyone actually found that file ever? No, but we use it all the time.
Further, for example if I was to buy a domain which used to host a service I really loved and then found it discontinued. I wanted to revive the project on my own. It would be very useful to return content to announce the users "We also loved the service
and we're in the process or rebuilding it, based on our examination, here's the sections that are the closest to what you searched for. If you cannot find what you're looking for, please let us know and we'll try to rebuild that. Thank you" and then content
to match the site section the users were probably searching for. But why not initially send them 302/301 redirect then? For the obvious reason that you're rebuilding the site as it used to be and do not want the links to rot and pages dropping off the search
engines. Rather than that, you return 200 OK which gives you some time to plan what to do with the dead links and replace them with real content.
If you really insist on doing this you can use an ISAPI Filter. The IIS SDK that is part of the Platform SDK may have examples you can start from. My guess is that there are already commercial filters out there that might do what you want, so do a google for
Hope this helps.
Thanks, that helped a lot [:D]
Dec 19, 2005 01:40 PM|dstgroup|LINK
Dec 19, 2005 02:25 PM|dstgroup|LINK
But these days, it doesn't serve anyones purpose to actually return a 404. Rather than that, one should probably return content. For example, for a hotlinked image one might return an image with text "sorry, but the image you were looking for is relocated.
Dec 19, 2005 07:02 PM|StrongTypes|LINK