现在这与我提出的问题紧密相关,并且answered yesterday。
这个问题/答案适用于测试asp.net错误(例如直接用于500,404,502等错误),但是当我尝试测试500.13之类的错误时 - Web服务器太忙,或者502.2 - 错误网关,我无法弄清楚如何做到这一点。
我认为asp.net生成/处理的错误与IIS(IIS处理子状态代码,如500.13等)之间存在明显差异。
有没有人对如何测试这些有任何想法?我发现你可以通过以下方式在web.config中处理这些子状态错误:
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear/>
<error statusCode="404" path="/errorPages/404.html" responseMode="Redirect"/>
<error statusCode="500" path="/errorPages/500.html" responseMode="Redirect"/>
<error statusCode="500" subStatusCode="13" path="/errorPages/500.13.html" responseMode="Redirect"/>
<error statusCode="502" subStatusCode="2" path="/errorPages/502.2.html" responseMode="Redirect"/>
</httpErrors>
回顾一下,我只是希望能够在.net中模拟/复制子状态错误,例如500.13或502.2,这样我就可以测试IIS返回我在web.config中指定的正确页面。
由于
丹
答案 0 :(得分:-1)
最简单的方法是在您的应用中创建一个返回status code you want的网页。
<强>的Page_Load 强> // HttpContext.Current.Response
Response.Clear();
if(Request.QueryString["code"] == null)
Response.StatusCode = someDefault;
else
Response.StatusCode = int.Parse(Request.QueryString["code"]);
您可以接收查询字符串参数,以便更容易自动化。