我在我的 JSF 2.2 webapp 中有一个自定义异常映射在 web.xml 中,如下所示。
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Project</display-name>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<session-config>
<!-- some codes-->
</session-config>
<error-page>
<exception-type>se.telenor.ocfd.service.api.exception.CustomNotFoundException</exception-type>
<location>/not_found.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.xhtml</location>
</error-page>
<error-page>
<location>/500.xhtml</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/session_timeout.xhtml</location>
</error-page>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我的例外是
@ApplicationException
public class CustomNotFoundException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CustomNotFoundException(String message, Throwable cause) {
super(message, cause);
}
public CustomNotFoundException(String message) {
super(message);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当异常发生时它会 …
我想实现一个自定义错误页面,该页面显示我自己的错误消息,而不是显示默认错误消息。
所以我在web.config文件中做了一些更改。这是我的web.config文件
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
<authentication mode="Forms">
<forms loginUrl="Account/Login"> …Run Code Online (Sandbox Code Playgroud) 具体来说,在原始响应触发功能(例如,状态为404)中,如何读取S3中存储的HTML文件并将其内容用作响应正文?
(我想像CloudFront一样手动返回自定义错误页面,但要基于cookie选择它)。
注意:S3中的HTML文件存储在我的网站的同一存储桶中。已启用OAI。
非常感谢你!
amazon-s3 custom-error-pages amazon-web-services aws-lambda aws-lambda-edge
我在 youtube 上看到如何处理自定义错误,但它是与 web.config 一起使用的,而在 dotnet core 2.2 中它没有此文件,或者我没有通过 Visual Studio 2019 找到它。
我想将简单的html页面添加为IIS的自定义错误。所以我添加404.html和500.html页面进行项目并添加下一个配置:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404" path="404.html" responseMode="File" />
<error statusCode="500" path="500.html" responseMode="File" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
HTML页面位于Views/Shared文件夹中。但是每次我走到一条不存在的道路时,我都会/foo/bar收到The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.不是我的错误消息。
对于ASP.Net的自定义错误,我添加下一个配置:
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Home/404">
<error statusCode="404" redirect="~/Home/404" />
<error statusCode="500" redirect="~/Home/500" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
并filters.Add(new HandleErrorAttribute());从FilterConfig文件中删除此行。
我发现html页面正确路径或更改/为的可能问题,\但没有人发现对我有用的解决方案。
我使用IIS7 +