title: 404 Redirection Troubleshooting
body: <p>I have Existing MVC Web Application url physically not exists (i.e. MyMVCSite/mypage.aspx. i need to redirect page on "error page" if invalid aspx enter by user, which not working in .aspx page condition but when unvalid action enter its work</p>
  
  <p>-) <em>MVCSite/InvalidePage --> Redirect to error Page MVCSite/error</em></p>
  
  <p>-) <em>MVCSite/InvalidePage.aspx --> Redirect to HomePage as  Page  MVCSite/InvalidePage.aspx</em></p>
  
  <p>I need last condition also redirects to Page MVCSite/error
  So this condition is also tried by me as URL physically not exist its also not work here...</p>
  
  <pre><code>protected void Application_BeginRequest(object sender, EventArgs e)
  { 
      if (sUrl.EndsWith(".aspx"))
      { 
          string[] path = sUrl.Split('/');
          if (!System.IO.File.Exists(Server.MapPath("test.aspx")))
          Response.Redirect("error");
      } 
  }
  </code></pre>
  
  <p>Furthermore i am unable to apply 404 exception in Application_Error event in Global.asax, this exception occurs many time so there is also a checkd of 404 - File does not exist due to some unknow reasons may be some images, css file not find which currently very hard to find</p>
  
  <pre><code>protected void Application_Error()
  {
      if (objException.Message != "File does not exist.") { //..... } 
  }
  </code></pre>
  
  <p>I am also apply custom errors in Web.config which also not work</p>
  
  <pre><code>&lt;customErrors mode="Off"&gt;
      &lt;error statusCode="404" redirect="Error/Index" /&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>Currently error page only occur when action name is wrong but if page name is wrong it redirect us on home page with wrong url
  <strong>Please advice many any other option using that i would resolve this issue</strong></p>