0

Currently I am using UrlRewritingNet.UrlRewrite dll for URL rewriting in Asp.Net #3.5.

Without using any special character it works fine ex. URL1. But after giving special characters in URL it throws Bad Request error ex. URL2

URL1: http://www.example.com/search/0253

URL2: http://www.example.com/search/0253:0253

To handle this error, I want to redirect it to some other Error Page, How can I do this?

DevD
  • 1
  • 1

2 Answers2

0

On IIS 7+ you can define error pages for all statuses, for 400 Bad Request :

<httpErrors>
  <error statusCode="400" path="/bad-request.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL"/>
</httpErrors>

or trough IIS console go to the error pages and add custom error page for status code 400 :

enter image description here

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
0

The best way is by using Web.config file like

<system.web>
    <!-- other system.web stuff -->
    <customErrors defaultRedirect="/Error404.aspx" mode="On" redirectMode="ResponseRewrite">
        <error redirect="/Error404.aspx" statusCode="404" />
    </customErrors>
</system.web>
<system.webServer>
    <!-- other system.webServer stuff -->
    <httpErrors errorMode="Custom">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/Error404.aspx" responseMode="ExecuteURL" />
    </httpErrors>
</system.webServer>

For more details click here

Community
  • 1
  • 1
Rahul
  • 5,603
  • 6
  • 34
  • 57