How to catch HTTP Error 400 - Bad Requests and redirect them properly on either asp.net application or in IIS 7.5

StackOverflow https://stackoverflow.com/questions/8066031

Domanda

How can i catch http 400 error bad requests either asp.net 4.0 code behind like in global.asax file or in IIS 7.5 and redirect them with 301 to the certain pages.

An example of bad request : http://www.monstermmorpg.com/Maps-Dark-Passage--------------------------------------------------..

You see that 2 ".." at the end make it bad request. I could not manage to capture it properly on either global.asax in asp.net code behind or IIS 7.5

any help is appreciated thank you.

È stato utile?

Soluzione

Have you tried via web.config?

<configuration>
      <system.web>
        <customErrors defaultRedirect="Error.htm"
                      mode="RemoteOnly">
          <error statusCode="400"
                 redirect="Redirect.aspx"/>
        </customErrors>
      </system.web>
    </configuration>

Error.htm would be a generic catch all error page. 400 errors would be sent to Redirect.aspx where you could do a redirect via code or html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top