I recently developed a 401 processing method that I think will work for you too. The problem with previous versions of .NET is that error pages do not return the correct error code, but only 302 to the specified page.
With .NET 3.5, your error handler can overwrite instead of redirecting with redirectMode:
<customErrors mode="On" defaultRedirect="/err.aspx" redirectMode="ResponseRewrite"> <error statusCode="404" redirect="/404.aspx"/> </customErrors>
Since all requests (including web service calls) now return the correct HTTP status code, you can correctly use the 404/401/500 code in your javascript.
Then in your client code (this is in jQuery and redirects to any errors not only 401s, but you get the idea):
$(document).ajaxError(function(event, XMLHttpRequest, ajaxOptions, thrownError) { window.location.href('/error.aspx'); });
source share