I have a try catch block to handle an error I am getting with my application. I would like a simple way of setting the response to status code 403 or forbidden and then either redirect the user to the login page or to a custom error page.
I am having some issue with once setting the status code and the redirect. Anyone have an example of setting the status code and then redirecting?
Duplicate: What should the HTTP response be when the resource is forbidden but there’s an alternate resource?
Sending Location header is only intended for 3xx (redirect) or 201 Created responses. Although it may work with most of the clients it's IMHO not how HTTP was designed.
If you really care about correct status codes and following HTTP specification why don't you respond with 303 See Other or use HTTP authentication.
This in C#, but the concept should be pretty much the same in most languages.