4
votes

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");
3
I'm having trouble trying to figure out why you would want the module to throw the 404? Is the module specifically designed to be the only thing on the page? - Chris Hammond
Yes it is. I'm developing a module for only my site and when an user does something weird, I just want an 404 to show up (which is my 404 page). - jerone

3 Answers

1
votes

just do this:

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

Simple solution for DNN

TabInfo errorPage404 = new TabController().GetTabByName("404 Error Page", this.PortalId);
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(errorPage404.TabID));
-1
votes

Maybe you need to clear response first?

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