NTS Forums

Please login or register.

Login with username, password and session length
 

News:

Welcome to the Newtek Technology Services Forum!


Author Topic: Custom Error Pages - Ack!  (Read 1170 times)

Offline ak732

  • Happily Verbose
  • Hero Member
  • *****
  • Posts: 1,476
  • Karma: +217/-39
    • Agile Web Technologies
Custom Error Pages - Ack!
« on: November 07, 2007, 04:25:58 PM »
All,

I'm trying to get custom error pages working for my asp.net 2.0 site.  I thought I'd start out with a simple 404 error handler.  It's been frustrating, to say the least.  I first tried using the "built in", asp.net solution via web.config:

Code: [Select]
<customErrors mode="On" defaultRedirect="~/errors/ServerError.aspx">
   <error statusCode="404" redirect="~/errors/NotFound.aspx"/>
</customErrors>

Problem with that is that it only works when the requested page is an aspx extension.  Other pages are sent to the default IIS 404 page.  So I set up a custom error page in Control Center (which just fronts for IIS's custom error page configuration). 

Okay, now both aspx page requests and non-aspx page requests are caught and redirected to my NotFound.aspx page.  The next problem is that the server responses are not what I want.  In this setup, by default, the server responses when using both IIS redirects and asp.net, web.config redirects, wind up being:

  requested page was aspx: 302 found
  requested page not aspx: 200 ok

What I really want is to always send a 404 (not found) response except for a few pages where I want to do a 301 (permanent redirect) to a page that has replaced the requested page.  For non aspx pages (those that were redirected to my error page by IIS), I can easily change the response headers to respond as desired.  But for aspx pages (those redirected to my error page via asp.net), my manipulation of the response headers fails; it always returns 200 ok. 

       Aaaaaaaaaaaaaaaaahhhhhhhhhh!  ???

So I tried switching the customErrors section to "Off" altogether and just using the IIS error page redirect.  No good.  Non-aspx pages still work (via IIS), but when an aspx page is requested, the user is sent to a page with: "server error in '/' application - resource not found" and some other crap.

I guess at this point, the easiest question is, how can I get the Control Center error page setup to work for both aspx and non-aspx page requests?  The more complicated question to ask is, how is everyone else handling this?

Thanks,
Andy
Andy

Offline ak732

  • Happily Verbose
  • Hero Member
  • *****
  • Posts: 1,476
  • Karma: +217/-39
    • Agile Web Technologies
Re: Custom Error Pages - Ack!
« Reply #1 on: November 17, 2007, 10:21:47 AM »
I still haven't found a solution for altering the HTTP response code from an ASP.NET custom error page.

I have a page NotFound.aspx.  I've configured both IIS and ASP.NET to redirect 404 errors to that page.  When IIS does the redirect, I can alter the response code to whatever I want and it works.  When ASP.NET does the redirect, the response code is always 302 (found) no matter what I do to modify the response code.

I'm guessing this has to do with the difference in how IIS and ASP.NET perform the initial redirect to NotFound.aspx.  It appears that IIS may be using a server transfer; not a redirect.  ASP.NET is doing a redirect.

For anyone that is working though similar issues, I've been blogging in great detail about using custom error pages to handle redirects here:

  http://www.agilewebtechnologies.com/blog/

If anyone has any suggestions as to how to get an ASP.NET custom error page to hand back a specific HTTP result code, please chime in here.

Thanks.
Andy