James Cadd
James Cadd

Reputation: 12216

How do I generate a 404 error from an HttpModule?

I have an ASP.NET HttpModule that handles HttpApplication.BeginRequest to redirect some requests to other files. Typically I'll do something like parse the request, write a file to HttpContext.Current.Response.OutputStream then call HttpApplication.CompleteRequest(). For some requests I can't find the relevant file - how do I return a 404 error?

Upvotes: 2

Views: 1895

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190945

Have you tried throw new HttpException(404, "Not Found");?

Upvotes: 6

Related Questions