Pre Exam Test Practice
Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
throwing an httpexception always sends back http 500 error using -'c#,asp.net,http,httpexception'
throwing an httpexception always sends back http 500 error ¬†using -'c#,asp.net,http,httpexception'
I'm trying to throw an HTTP 403 error code back at the client. I've read that HttpException is the cleanest way to accomplish this, but it's not working for me. I throw the exception from within a page like this:
throw new HttpException(403,"You must be logged in to access this resource.");
However, this will only give a standard ASP.Net stack trace(with 500 error) when CustomErrors is off. If CustomErrors is on, then this will not redirect to the page I have setup to be displayed when a 403 error occurs. Should I forget about HttpException and instead set all the HTTP codes myself? How do I fix this?
The custom errors part of my Web.Config is this:
<customErrors mode="On" defaultRedirect="GenericErrorPage.html">
¬†¬†¬†¬†¬†¬†<error statusCode="403" redirect="Forbidden.html" />
Instead of getting Forbidden.html, I'll get GenericErrorPage.html
Sep 7, 2015
to add a comment.
Related Hot Questions
Government Jobs Opening