4

我想从我的模块中抛出一个 404 file not found 异常,但是每个异常都被 DNN 捕获并且没有显示我的 404.aspx 页面(仅来自 DNN 的错误页面)。

在我的 web.config 中,我添加了:

<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>

打开不存在的页面时效果很好。但是尝试对我的模块做同样的事情并没有给我同样的结果......

我尝试了以下但没有成功:

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

3 回答 3

1

这样做:

Response.StatusCode = 404;
Response.End(); 
于 2012-03-13T17:28:07.647 回答
1

DNN 的简单解决方案

TabInfo errorPage404 = new TabController().GetTabByName("404 Error Page", this.PortalId);
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(errorPage404.TabID));
于 2018-09-17T12:04:09.753 回答
-1

也许你需要先明确回应?

Response.Clear();
Response.StatusCode = 404;
Response.End(); 
于 2012-03-13T22:52:38.717 回答