Redirecting 401 output

Topics: Developer Forum
Nov 27, 2007 at 8:40 PM

I want to take a page that would otherwise generate a 401 error, and instead of returning a 401, return a custom page - containing a client-side redirect to another page.

By way of example: if logging into http://site/WindowsAuthLogin.aspx?ReturnURL=foo (with Windows authentication) fails, instead of returning a default 401, I want to return a page which will trigger a redirect to http://site/FormsLogin.aspx?ReturnURL=foo. This can't be a 302 redirect because the browser needs the 401 to send the credentials, and it can't be a custom error page in IIS because I need to capture the ReturnURL value.

(I am aware of the alternative of capturing the original returnURL value in the global.asax, but I'd like to see if this can be done without changing the code.)

Unfortunately, I don't think I can do this with the IIRF. Do you have any idea if this is possible with an ISAPI filter, and if so, is there example code out there other than just what's in IIRF now?