Returning to the main page when accessing an invalid url

0

How do I redirect the user to the main page of the app if it tries to access an invalid url . For example, www.teste/teste.html , in case the page does not exist then system directs the user to www.teste/index.html , in case I am using asp.net MVC5 .

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Views/Home/Index">
  <error statusCode="500" redirect="~/Erro" />
</customErrors>

When I access a non-existent page it returns the message:

  

400 bad request

Can anyone help me with this question?

    
asked by anonymous 12.09.2017 / 18:01

1 answer

0

In my case I pass a parameter to my action that returns the custom error screen, but based on your sample code I believe the path is not correct, if your controller calls "Error" and your Index method is your screen then just remove that tilde before the bar. below looks like I did:

<customErrors mode="On" defaultRedirect="/Home/_Error/">
      <error statusCode="500" redirect="/Home/_Error/500" />
      <error statusCode="404" redirect="/Home/_Error/404" />
    </customErrors>
    
13.09.2017 / 02:42