如何在服务堆栈异常中自定义 HTML 响应?
How to customize HTML response in service stack exception?
我有一个旧应用程序使用隐藏的 iframe 将内容上传到网络服务器。在应用程序启动期间,document.domain 在浏览器中设置为特定值。来自服务器的任何要包含在 iframe 中的 html 响应也需要将 document.domain 设置为相同的值,否则将违反同源策略。在出现异常的情况下,服务堆栈将采用 DTO 并在其周围生成一些 HTML。但是,此 html 不包含将 document.domain 设置为所需值的脚本。那么我的问题是,是否可以自定义错误发回的响应的 HTML?
查看文档:
https://docs.servicestack.net/error-handling#custom-exceptions
它说我们可以 "throw or return an HttpError letting you customize the Http Headers and Status Code and HTTP Response body to get exactly what you want on the wire"。我在 "HttpError with a Custom Response DTO" (https://docs.servicestack.net/error-handling#httperror-with-a-custom-response-dto) 的副标题下看到了使用自定义 DTO 的示例,它将被送入服务堆栈,并将出现在 HTML 的 body 中.但是,我能否获得更多控制权,以便我可以自定义 HTML 以在脚本标记中包含一些自定义 javascript(document.domain 设置)?
如果您想 return 自定义 HTML 错误页面,请查看 Fallback Error Pages where you can assign which custom Error page to return when using either #Script Pages or ServiceStack.Razor。
我有一个旧应用程序使用隐藏的 iframe 将内容上传到网络服务器。在应用程序启动期间,document.domain 在浏览器中设置为特定值。来自服务器的任何要包含在 iframe 中的 html 响应也需要将 document.domain 设置为相同的值,否则将违反同源策略。在出现异常的情况下,服务堆栈将采用 DTO 并在其周围生成一些 HTML。但是,此 html 不包含将 document.domain 设置为所需值的脚本。那么我的问题是,是否可以自定义错误发回的响应的 HTML?
查看文档:
https://docs.servicestack.net/error-handling#custom-exceptions
它说我们可以 "throw or return an HttpError letting you customize the Http Headers and Status Code and HTTP Response body to get exactly what you want on the wire"。我在 "HttpError with a Custom Response DTO" (https://docs.servicestack.net/error-handling#httperror-with-a-custom-response-dto) 的副标题下看到了使用自定义 DTO 的示例,它将被送入服务堆栈,并将出现在 HTML 的 body 中.但是,我能否获得更多控制权,以便我可以自定义 HTML 以在脚本标记中包含一些自定义 javascript(document.domain 设置)?
如果您想 return 自定义 HTML 错误页面,请查看 Fallback Error Pages where you can assign which custom Error page to return when using either #Script Pages or ServiceStack.Razor。