Search code examples
c#-4.0dotnetnukedotnetnuke-moduledotnetnuke-6

How to throw 404 in DotNetNuke module


I want to throw an 404 file not found exception from my module, but every exception is caught by DNN and does not show me my 404.aspx page (only the error page from DNN).

In my web.config I've added:

<httpErrors errorMode="Custom" defaultResponseMode="File">
  <remove statusCode="404" />
  <error statusCode="404" prefixLanguageFilePath="" path="/404.aspx" responseMode="ExecuteURL" />
</httpErrors>

&

<customErrors mode="On">
  <error statusCode="404" redirect="~/404.aspx" />
</customErrors>

Which work great when opening a page that does not exist. But trying to do the same thing with my module does not give me the same result...

I've tried the following without success:

throw new HttpException(404, "Not Found");

Solution

  • just do this:

    Response.StatusCode = 404;
    Response.End();