Wednesday, March 28, 2012

How do I intercept Authentication Failed exception from web-service call

Will somebody please put me out of my misery. I think this might be a common problem, but I've spent 30mins searching the forum and I can't find a solution...

I have forms-authenticated web app with a page that makes AJAX client-side calls to a web-service that is part of the same application and hence (I assume) is protected by the forms authentication. The problem occurs when the forms authentication ticket has expired. If a user action invokes a call to the web-service they get a message box quoting InvalidOperationException and Authentication Failed etc. I want to try and intercept this exception and re-direct to the login page as usual. I can't see how to do this. I've tried adding a <location> tag to the web.config to exclude the web-service asmx file from the authorisation, but this doesn't work.

The HTTP logs show a 500 internal server error along with this message:

"@dotnet.itags.org._Error(false,"Authentication failed.",null,"System.InvalidOperationException")Error_@dotnet.itags.org."

How can I intercept this exception??

I'll simplify my question:

How do you chaps manage to make AJAX web-service calls co-exist with forms authentication?

If the authentication ticket expires, how do you handle this error from the client (browser)?

I await your prompt and courteous replies!


OK, so I didn't realise you can specifiy a failure callback as well as a success callback when calling a web-service.

That's all I needed, thanks to no-one for helpingIndifferent

No comments:

Post a Comment