Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Common/DefaultRedirectErrorPage.aspx">
- void Application_Error(object sender, EventArgs e)
- {
- }
- <customErrors mode="On" defaultRedirect="~/error.aspx" >
- <error statusCode="404" redirect="~/lost.aspx" />
- <error statusCode="500" redirect="~/error.aspx" />
- </customErrors>
- protected void Application_Error(object sender, EventArgs e)
- {
- var context = Context;
- var error = context.Server.GetLastError() as HttpException;
- var statusCode = error.GetHttpCode().ToString();
- // we can still use the web.config custom errors information to
- // decide whether to redirect
- var config = (CustomErrorsSection)WebConfigurationManager.GetSection("system.web/customErrors");
- if (config.Mode == CustomErrorsMode.On ||
- (config.Mode == CustomErrorsMode.RemoteOnly && context.Request.Url.Host != "localhost"))
- {
- // set the response status code
- context.Response.StatusCode = error.GetHttpCode();
- // Server.Transfer to correct ASPX file for error
- if (config.Errors[statusCode] != null)
- {
- HttpContext.Current.Server.Transfer(config.Errors[statusCode].Redirect);
- }
- else
- HttpContext.Current.Server.Transfer(config.DefaultRedirect);
- }
- }
- protected void Page_PreRender(object sender, EventArgs e)
- {
- Response.Status = "404 Lost";
- Response.StatusCode = 404;
- }
Add Comment
Please, Sign In to add comment