I am using httpErrors in my web.config and have the following:
<error statusCode="404" subStatusCode="1" responseMode="Redirect" path="http://www.somewhere-else.com" />
Doing the following in a custom action result, works fine:
Response.StatusCode = 404;
Response.SubStatusCode = 1;
But the code that determines whether the 404 redirect is necessary is a bit further down the stack so rather than returning an actionresult, I woul prefer to throw an exception and halt further execution.
For error entries in httpErrors without a subStatusCode, I can throw the appropriate HttpException and it works as expected:
throw new HttpException(400, "Bad Request");
But I need the subStatusCode. I have tried setting Response.SubStatusCode before throwing an HttpException but it gets ignored and the default 404 error page is shown.
Any way around this?
(btw, I know subStatusCode is only internal and not exposed to client)