Guest User

Untitled

a guest
May 20th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Common/DefaultRedirectErrorPage.aspx">
  2.  
  3. void Application_Error(object sender, EventArgs e)
  4. {
  5. }
  6.  
  7. <customErrors mode="On" defaultRedirect="~/error.aspx" >
  8. <error statusCode="404" redirect="~/lost.aspx" />
  9. <error statusCode="500" redirect="~/error.aspx" />
  10. </customErrors>
  11.  
  12. protected void Application_Error(object sender, EventArgs e)
  13. {
  14. var context = Context;
  15.  
  16.  
  17. var error = context.Server.GetLastError() as HttpException;
  18. var statusCode = error.GetHttpCode().ToString();
  19.  
  20. // we can still use the web.config custom errors information to
  21. // decide whether to redirect
  22. var config = (CustomErrorsSection)WebConfigurationManager.GetSection("system.web/customErrors");
  23. if (config.Mode == CustomErrorsMode.On ||
  24. (config.Mode == CustomErrorsMode.RemoteOnly && context.Request.Url.Host != "localhost"))
  25. {
  26. // set the response status code
  27. context.Response.StatusCode = error.GetHttpCode();
  28.  
  29. // Server.Transfer to correct ASPX file for error
  30. if (config.Errors[statusCode] != null)
  31. {
  32.  
  33. HttpContext.Current.Server.Transfer(config.Errors[statusCode].Redirect);
  34. }
  35. else
  36. HttpContext.Current.Server.Transfer(config.DefaultRedirect);
  37. }
  38. }
  39.  
  40. protected void Page_PreRender(object sender, EventArgs e)
  41. {
  42. Response.Status = "404 Lost";
  43. Response.StatusCode = 404;
  44.  
  45. }
Add Comment
Please, Sign In to add comment