Returning to the main page when accessing an invalid url

Asked

Viewed 61 times

0

As I redirect the user to the main page of the application, in case it tries to access a url invalid. 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’m 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

Could someone help me with that doubt?

  • 1

    See if that helps you. https://answall.com/questions/47641/asp-net-mvc-bad-request

1 answer

0

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.