1. Add following section in web.config
<customErrors mode="On">
<error statusCode="404" redirect="~/error404.aspx" />
</customErrors>
2. Get wrong page from query string
string from = Request.QueryString["aspxerrorpath"];
http://rayaspnet.blogspot.ca/2012/08/handling-exceptions-and-404-errors-in.html