如何在IIS服务器中禁用自定义错误页面生成

时间:2017-01-31 07:31:03

标签: spring apache iis spring-boot webserver

我的Spring Boot应用程序在IIS Server上运行,生成自定义错误页面,用于在标头处查找错误代码401。我想禁用它。响应数据中不应有自定义错误页面。 Apache server中存在默认行为。虽然IIS Server可以配置为阻止为远程请求生成自定义错误页面,但我希望从我的应用程序配置它(Web配置点可能是)。是Spring有可能吗?

2 个答案:

答案 0 :(得分:0)

在你的web.xml中添加:

<error-page>
    <error-code>401</error-code>
    <location>/errors/unauthorised</location>
</error-page>

然后添加一个这样的控制器:

@Controller
@RequestMapping("/errors")
public class ApplicationExceptionHandler {

    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    @RequestMapping("unauthorised")
    public ModelAndView unauthorizedError(){
        return new ModelAndView("errors/error.jsp");
    }
}

答案 1 :(得分:0)

web.config文件添加到您应用的网络应用目录(app/src/main/webapp)web.config文件应包含:

<configuration>
   <system.webServer>
      <httpErrors errorMode="Detailed" existingResponse="Auto" />
   </system.webServer>
</configuration>

这会导致IIS web server将错误模式设置为'Detailed',这会阻止生成自定义错误页面。