2

In web.config of my ASP.NET website I have customErrors turned on and set to redirect to a specific action in case of HTTP 404:

now I start Fiddler and in my browser query some URL that yields HTTP 404. Fiddler clearly shows that first the browser queries that URL and gets HTTP 302 with the path to <...>/Error/FileNotFound and queries that and finally receives HTTP 200.

So effectively the original HTTP 404 disappears and I get HTTP 302 followed by HTTP 200.

Meanwhile if I query some invalid address from StackOverflow (like https://stackoverflow.com/ques/ask) I get HTTP 404 in a single request. I mention this because StackOverflow uses ASP.NET too.

How do I use customErrors in IIS to get HTTP 404 instead of HTTP 302 followed by HTTP 200?

4

1 に答える 1

3

ノードではcustomErrors、次の属性を設定できます。

redirectMode="ResponseRewrite"

これにより、ページがリダイレクトされなくなり、要求されたページの代わりにエラーページが書き込まれます。

注意:404エラーページとして使用されているページ自体が、実際にはコードビハインドで404ステータスコードを返すことも確認する必要があります。MS書き換えサポートは、ステータスコードを自動的に通過させません。リンクを参照してください。

https://connect.microsoft.com/VisualStudio/feedback/details/507171/asp-net-returns-incorrect-status-code-even-with-redirectmode-responserewrite

于 2013-01-24T11:59:36.507 に答える