Asp.net Custom 403 Error Page
Contents |
here for a quick overview of the site Help Center Detailed answers
Custom 404 Error Page
to any questions you might have Meta Discuss the workings custom 401 error page and policies of this site About Us Learn more about Stack Overflow the company Business
Custom 500 Error Page
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack httperrors errormode custom Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Custom 403 error page in ASP.NET MVC 2 up vote 2 down vote favorite I want to show a custom 403 page in my ASP.NET web.config httperrors MVC 2 application. I followed following link. I added following to my config file: your web site. The custom errors can be set or overridden on a site wide or directory-by-directory basis. While some web.config sections require that the directory is set as an application, this isn't one of them. A simple web.config with a httpErrors section may be placed httperrors web.config example in any directory, and the directory does NOT need to be set as an application. What are http errors? HTTP errors are returned to the client when something goes wrong on the server. Error status codes are returned if the requested file isn't found (404), or due to coding errors in the web page http://stackoverflow.com/questions/25849167/custom-403-error-page-in-asp-net-mvc-2 (500), and due to temporary issues such as failed database connections (500). The most common errors are 404 (file not found) and 500 (application) errors. Custom 404 and 500 errors are typically used to provide a friendlier error message to your users. Custom 404 and 500 errors could also redirect the user to the default (or any) page, and are sometimes used to notify the web site https://www.stokia.com/support/misc/web-config-custom-httperrors.aspx administrator of problems on the web site. If you wish to configure custom errors for your site, or even just for a single directory in your site, please follow the directions on this page. 400 Error (bad request) 401 Error (unauthorized) 403 Error (forbidden) 404 Error (not found) 500 Error (internal server error) How it's done Example custom HTTP errors. Comments are enclosed in and are not required. Capture and return specific error types ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/MVC/Forcing IIS 7.0 to redirect to a custom page when 403 http error is r... Forcing IIS 7.0 to redirect to a custom page when 403 http error is raised [Answered]RSS 5 replies Last post Aug 11, 2014 10:01 PM by Starain chen - MSFT ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Related Links GuidanceSamplesVideos Reply johnjohn1231... Member 474 Points 2431 Posts Forcing IIS 7.0 to redirect to a custom page when 403 http error is raised Aug 08, 2014 10:15 AM|johnjohn123123|LINK I am working on an asp.net mvc web application, and inside my application I have defined a custom authorization attribute , which will return 403 error if the user is not authorized as follow; and I provide two response types depending if the request is Ajax or not:- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class CheckUserPermissionsAttribute : AuthorizeAttribute { public string Model { get; set; } public string Action { get; set; } protected override bool AuthorizeCore(HttpContextBase httpContext) { //code goes here ....... } protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { if (filterContext.HttpContext.Request.IsAjaxRequest()) { filterContext.Result = new HttpStatusCodeResult(403, "Sorry, you do not have the required permission to perform this action."); } else { var viewResult = new ViewResult(); viewResult.ViewName = "~/Views/Errors/_Unauthorized.cshtml"; filterContext.HttpContext.Response.StatusCode = 403; filterContext.Result = viewResult; } } } The problem is that my current approach works fine on my development environment (not deployed to iis), but when I deploy my application to the staging server on IIS 7 ; then all my http requests (non-ajax) that have 403 error code will be redirect to the following page, 403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied so i added the following to my web.config file:- Asp.net Mvc Controller Return 403
Web.config Custom Error Page