如何在DotNetNuke模块中抛出404

问题描述 投票:3回答:3

我想从我的模块中抛出一个404文件未找到异常,但每个异常都被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");
c#-4.0 dotnetnuke dotnetnuke-module dotnetnuke-6
3个回答
2
投票

这样做:

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

0
投票

也许你需要先清除回复?

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

0
投票

DNN的简单解决方案

TabInfo errorPage404 = new TabController().GetTabByName("404 Error Page", this.PortalId);
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(errorPage404.TabID));
© www.soinside.com 2019 - 2024. All rights reserved.