我很好奇是否有人考虑过桌面应用程序错误消息中的措辞.作为一名开发人员,我总是穿上我的程序员帽子并用一个看起来像机器人的方言显示给用户.
例如:
这些都不是"友好的应用".有没有人知道在较少机器人语言中的任何资源或短语错误方法 - 对于IO问题,数据库问题,空引用等常见错误.
正如其他地方所建议的那样 ,我在自定义错误配置中使用redirectMode = ResponseRewrite,因此我的自定义错误页面可以访问异常信息.这有点像魅力一段时间了.
在添加更多"帮助用户从错误中恢复"类型功能时,我们需要一段先前存储在Session中的信息.实现这一点时,我发现当redirectMode = ResponseRewrite时,Session的各种途径以null结尾,但是当redirectMode = ResponseRedirect(或未定义)时,它们都被填充.
谁知道为什么?我们必须在具有异常信息(ResponseRewrite)或具有Session(ResponseRedirect)之间进行选择,这似乎很奇怪.
关于Rich Custom Error处理的MSDN文章告诉我,当控制传递方法是Server.Transfer时,Session才可用,这就是我假设在引擎盖下使用的ResponseRewrite.显然事实并非如此.
asp.net exception-handling web-config custom-errors redirectmode
我使用ASP.NET的<customErrors>指令使用通用错误页面.
<customErrors mode="On" defaultRedirect="500.html" redirectMode="ResponseRewrite">
</customErrors>
Run Code Online (Sandbox Code Playgroud)
问题 - 发生错误时,此页面不会返回HTTP状态"500".它来自200.所以链接检查器和蜘蛛没有看到有任何问题.
如何将500 HTTP状态与静态500.html页面一起发送?
要求:
在我在共享主机提供程序中发布的ASP.NET 3.5网站中,我已经配置了我的web.config文件,如下所示:
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="AccessDenied.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>
Run Code Online (Sandbox Code Playgroud)
如果不存在(如"www.example.com/NotExistPage.aspx")的用户请求的页面,因为我们预计用户会被重定向到FileNotFound.htm页.
但是如果用户请求某个地址,例如:"www.example.com/NotExistDirectory"而没有.aspx扩展名,则用户将遇到IIS 7.5错误页面:
HTTP错误404.0 - 未找到您要查找的资源已被删除,名称已更改或暂时不可用.
已淘汰的错误信息:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://www.example.com:80/NotExistDirectory
Physical Path D:\Websites\example\example.com\wwwroot\NotExistDirectory
Logon Method Anonymous
Logon User Anonymous
Run Code Online (Sandbox Code Playgroud)
这是一个黄页,不是用户友好的,我们没想到.
我想知道在webconfig中设置customeError不支持这种类型的地址吗?如何防止用户看到此黄页.
编辑: 感谢大卫的回答,但我找到了实际的原因和正确的解决方案.请看我的答案.
我正在尝试为MVC站点设置自定义错误.我有404页面工作正常,但在测试服务器错误时,我得到默认消息:
很抱歉,在执行您的要求时发生了一个错误.
而不是我的自定义页面.
我在web.config中设置了这个:
<customErrors mode="On" defaultRedirect="~/Error/500">
<error statusCode="404" redirect="~/Error/404" />
<error statusCode="500" redirect="~/Error/500" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
我的错误控制器如下:
public class ErrorController : Controller
{
[ActionName("404")]
public ActionResult NotFound()
{
return View();
}
[ActionName("500")]
public ActionResult ServerError()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在500通过在我的一个视图中抛出异常来测试错误页面:
[ActionName("contact-us")]
public ActionResult ContactUs()
{
throw new DivideByZeroException();
return View();
}
Run Code Online (Sandbox Code Playgroud)
为什么只处理404错误?如何显示错误页面以查找500错误?
脚本
我有一个自定义规则来验证订单的运费:
public class OrderValidator : BaseValidator<Order>
{
private string CustomInfo { get; set; }
public OrderValidator()
{
//here I call the custom validation method and I try to add the CustomInfo string in the message
RuleFor(order => order.ShippingCost).Cascade(CascadeMode.StopOnFirstFailure).NotNull().Must(
(order, shippingCost) => CheckOrderShippingCost(order, shippingCost)
).WithMessage("{PropertyName} not set or not correct: {PropertyValue}." + (String.IsNullOrEmpty(CustomInfo) ? "" : " " + CustomInfo));
}
//this is the custom validation method
private bool CheckOrderShippingCost(Order o, decimal shippingCost)
{
bool res = false;
try
{ …Run Code Online (Sandbox Code Playgroud) 这可能是一个有点奇怪的问题,但我会试一试:
帮助,我的Visual Studio 2008/ASP.NET给了我GERMAN错误消息.除了翻译往往不如原始文本这样的事实,我无法搜索这些并在互联网上找到我的问题的相关答案.
那么:如何将德语Visual Studio 2008标准版切换为英语本地人?
更新 - 只是为了说清楚:
我是德国开发人员,与德国Windows Vista合作......我也有德语版的Visual Studio,所以一切都是德语并不奇怪.只是不想那样......但是必须有一种方法将英语本地人安装到我的Visual Studio中吗?或卸载德语,以便使用默认的英语?!?
(顺便说一句:对于SQL Server Management Studio也是如此.F**k"Sichten".我想要"视图".这就是你真正称呼它们的方式.没有人说"Sichten",甚至在德国都没有,甚至没有虽然它被正确翻译).
locale internationalization custom-errors visual-studio-2008
我有一个自定义验证器,我试图输出错误信息,但它失败但无法这样做.有人可以告诉我,如果我在正确的地方这样做.
class User < ActiveRecord::Base
self.table_name = "user"
attr_accessible :name, :ip, :printer_port, :scanner_port
validates :name, :presence => true,
:length => { :maximum => 75 },
:uniqueness => true
validates :ip, :length => { :maximum => 75 },
:allow_nil => true
validates :printer_port, :presence => true, :if => :has_association?
validates :scanner_port, :presence => true, :if => :has_association?
def has_association?
ip != nil
end
end
Run Code Online (Sandbox Code Playgroud)
我有如下:
validates :printer_port, :presence => true, :message => "can't be blank", :if => :has_wfm_association?
Run Code Online (Sandbox Code Playgroud)
但是收到了一个错误
Unknown validator: …Run Code Online (Sandbox Code Playgroud) 我在asp.net mvc app中使用自定义动作过滤器将http状态代码422和json验证错误列表(基本上是序列化模型状态字典)返回给客户端,我在jQuery中使用全局ajaxError处理程序处理它.
所有这些都适用于开发环境,但我的问题是当自定义错误模式打开(<system.webServer>/<httpErrors errorMode="Custom">)时,IIS用文本替换响应(json)"自定义错误模块无法识别此错误."
如果状态代码为422,我很难正确配置IIS以传递原始响应.任何人都做了类似的事情吗?
我一直在将我的一些Web应用程序整合到一个主要的ASP.NET MVC项目中; 将其中一些分配给单独的区域,以便可以通过子域访问它们.
使用这个(很有用)资源(https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging),我已经设置了customErrors和httpErrors在Web.config,使自定义错误页面显示.效果很好.
我将在Area/subdomain中使用不同的布局/样式,所以我想知道: 如何让Area显示自己的错误页面?
使用当前设置,所有子域都将显示添加到customErrors和httpErrors部分的主要自定义错误集(403.html,404.html等); 但我更喜欢为某些子域定制错误页面.(例如,如果其中一个区域完全由一个单独的域处理,那么提供常规错误页面是不切实际的.)
更新: 这是根据请求使用代码的方案.感谢Ben Foster,他在这里提供了很好的指导:http://benfoster.io/blog/aspnet-mvc-custom-error-pages 2.我已经为customErrors设置了代码,但是没有相应的httpErrors ...为了简洁起见.
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/500.aspx">
<error statusCode="404" redirect="~/404.aspx" />
<error statusCode="500" redirect="~/500.aspx" />
</customErrors>
</system.web>
<location path="MyArea1">
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Areas/MyArea1/500.aspx">
<error statusCode="404" redirect="~/Areas/MyArea1/404.aspx" />
<error statusCode="500" redirect="~/Areas/MyArea1/500.aspx" />
</customErrors>
</system.web>
</location>
<location path="MyArea2">
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Areas/MyArea2/500.aspx">
<error statusCode="404" redirect="~/Areas/MyArea2/404.aspx" />
<error statusCode="500" redirect="~/Areas/MyArea2/500.aspx" />
</customErrors>
</system.web>
</location> …Run Code Online (Sandbox Code Playgroud) custom-errors ×10
asp.net ×3
web-config ×3
c# ×2
iis-7.5 ×2
asp.net-mvc ×1
exception ×1
iis ×1
locale ×1
redirectmode ×1
rspec2 ×1