Posted on 04/02/2026 09:15:13
One thing to be aware of in terms of redirect - in .net 4, doing a redirect also throws a ThreadAborted exception that causes the remaining code to not execute. This behavior has lots of issues why it works different in asp.net core.
So - if you do a redirect in a template in asp.net core, the code continues to execute and the result is returned to the middleware pipeline that will either send it out or continue with the next middleware. The redirect merely adds the location header to the http response header, and the browser will redirect to that location when it receives the output. But all the code after the redirect will probably still execute - and the resulting html might also be send to the browser despite your redirect.
So if you use this redirect pattern in templates, which is architectual late, you might also get some unwanted side affects of sending data that should not be sent etc. So if you use it for things where the user should not see some data, be sure to check.