简体   繁体   中英

I am using UrlRewritingNet.UrlRewrite dll, how to redirect to Error page when bad request get fired?

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?

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 :

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM