に基づいて、サーバー上のすべてのサイトで特定の要求に対して404 応答を生成しようとしていますHttpRequest.UserAgent。
以下のコードを含むIHttpModuleサーバーのグローバルに を構成しました。web.config
private void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
if (isBot(context.Request.UserAgent))
{
System.Diagnostics.EventLog.WriteEntry(
"Application",
"\nBotRequestChecker -- request 404d\n" + "Url: " +
context.Request.Url + "\nUserAgent: " + context.Request.UserAgent,
EventLogEntryType.Information);
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not Found";
context.ApplicationInstance.CompleteRequest();
}
}
ブラウザで を設定しUser-Agentてページにアクセスすると、イベント ログにエントリが記録されますが、そのページも 404 ステータスなしで返されます。
私が見逃しているものについて何か考えはありますか?
アップデート:
すべてのサイトではなく、単一のサイト (サイトの )にIHttpModule追加すると機能するようです。web.config
更新 2: IIS6ではなく、 IIS7サーバーIHttpModule上の単一のサイトでのみ機能し
ます。