Target: I was working on custom Login page to redirect user on specific site based on their user type (e.g Admin User, Manager User etc) using Claims Based Authentication using response.redirect in try catch block in c# and i was getting following error
[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
also my thread was being Aborted but i was able to redirect on specific site.
So the error was very weird. I analyze the code again and found solution 🙂
Solution:
I did some try with code and found when i was commenting ‘try’-‘catch’ block it was working fine. But its quite mandatory for me to use ‘try’-‘catch’ block.
So i found another work around to get user redirected successfully on specific site.
In Response.Redirect, i passed second parameter as “False”, the reason behind this is – the thread of page from which i was redirecting to a new page/site was not executed completely and i was redirecting it to a new page/site so the error was coming.
Below is a sample code snippet which i used.
Hope this will help someone…