开发者

Faking Http Sub Status Codes in IIS/.net for testing

开发者 https://www.devze.com 2023-04-12 06:55 出处:网络
Now this is tightly coupled to the question I raised and had answered yesterday. This question/answer works well for t开发者_Python百科esting asp.net errors (such as straight for 500, 404, 502 etc e

Now this is tightly coupled to the question I raised and had answered yesterday.

This question/answer works well for t开发者_Python百科esting asp.net errors (such as straight for 500, 404, 502 etc errors) but when I have tried to test errors such as 500.13 - Web server is too busy, or 502.2 - Bad gateway, I can't work out how to do this.

I think there is a clear difference between error generated/handled by asp.net and those by IIS (IIS dealing with the sub status codes such as 500.13 etc.).

Has anyone any ideas on how to test these? I found to handle these sub status errors in the web.config you do so in the following way:

<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>

To recap, I simply want to be able to simulate/replicate an sub status error such as 500.13 or 502.2 in .net so that I can test IIS returns the correct page I have specified in the web.config.

Thanks

Dan


Easiest way would be to create a page in your app that returns the 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"]);

You could receive a query string parameter so that it would be easier to automate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号