.Net 默认重定向到特定于区域设置的错误页面
我有一个 ASP.Net Web 表单应用程序,它使用 .Net 全球化功能在不同区域设置中提供 .aspx 页面。我定义了自定义错误,因为
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm">
我更喜欢使用非 .Net 页面进行 defaultRedirect,以防止潜在的无限循环,以防错误页面本身生成错误,因此我将目标定为静态 .htm 页面。但是,我想在用户最初请求的区域设置中呈现该页面,其中区域设置是根据查询字符串确定的。
实现这一目标的最佳方法是什么?
我已经考虑过这些选项,但我对其他选项感兴趣:
- 重定向到其他一些可以运行服务器端逻辑的应用程序/域,以重定向到或呈现特定于区域设置的响应(似乎有点矫枉过正)
- 使用客户端代码(JavaScript )呈现特定于区域设置的内容(不过,这不适用于禁用 JavaScript 的浏览器,我希望它也适用于这些用户)
- 使静态错误页面以多种语言显示文本 - 在一种语言上显示所有语言文本页面(不过,我更喜欢只在一种语言环境中显示文本)
I have an ASP.Net webforms application that uses the .Net globalization features to deliver .aspx pages in different locales. I have custom errors defined as
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm">
I prefer using a non-.Net page for the defaultRedirect to prevent the potential for infinite loops, in case the error page itself generates an error, so I have targeted a static .htm page. However, I would like to render that page in the locale that the user originally requested, where the locale is determined from a querystring.
What is the best way to accomplish this?
I have considered these options, but I am interested in other options:
- Redirect to some other app/domain that can run server-side logic to redirect to or render a locale-specific response (seems like overkill)
- Use client-side code (JavaScript) to render locale-specific content (doesn't work for JavaScript-disabled browsers, though, and I would like it to work for these users too)
- Make the static error page display text in multiple languages--show all language text on one page (I prefer to only show text in one locale, though)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的项目文件结构具有特定于语言的文件夹,一种解决方案是创建一个 web.config,其中仅在每个语言文件夹中指定
部分示例项目结构
If your project file structure has language specific folders, one solution is to create a web.config with just the
<customErrors />
section specified in each language folderExample Project Structure
如果您可以创建一个动态页面来显示错误信息,并考虑本地化和其他事情,我认为这是最好的方法。
您可以处理global.asax上的错误,我们开发您自己的httpmodule(两种方式都有效)您可以通过一种出色且动态的方式管理应用程序错误,控制所有过程。
包括确定当前语言来决定可能的重定向,或者例如显示有关不同类型错误的不同消息。
在我看来,我开始使用一种解决方案来解决问题,该解决方案使我可以灵活地决定如何处理不同的情况。
if you can create a dynamic page for error information, taking care about the localization and other things, i think that is the best way.
You can handle errors on global.asax our developing your own httpmodule (both ways are valid) you can manage the application errors by a great and dynamic way, taking control of all process.
including determine current laguage to decide about a possible redirect, or for example display different messages about different kind of errors.
in my opinion i start resolving a problem with a solution that givesme flexibility to deside how can i handle on different cases.
我得出的结论是,最佳实践通常遵循以下问题的答案中概述的方法,仅传输到 .htm 页面而不是 .aspx 页面:
ASP.NET 2.0:编写错误页面的最佳实践
I have concluded that the best practice is to generally follow the method outlined in the answer to the following question, only transfer to a .htm page instead of an .aspx page:
ASP.NET 2.0 : Best Practice for writing Error Page