Faking Http Status Codes in IIS/.net for testing

拥有回忆 提交于 2019-12-01 09:33:18

Try something like:

    protected void Page_Load(object sender, EventArgs e)
    {
        var rawErorStatus = HttpContext.Current.Request.QueryString.Get("errorStatus");

        int errorStatus;
        if (int.TryParse(rawErorStatus, out errorStatus))
        {
            throw new HttpException(errorStatus, "Error");
        }
    }

Found this at the following page: http://aspnetresources.com/articles/CustomErrorPages

Paul Kohler

This won't work for all but you can flesh it out... The cache setting is important otherwise the last code they try could be cached by the browser etc.

Create a basic page, e.g. "FakeError.aspx":

<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server" language="c#">

  protected void Page_Load(object sender, EventArgs e)
  {
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.StatusCode = Convert.ToInt32(Request.QueryString["code"]);
    Response.End();
  }

</script>
</html>

Then hit it...

Like I said, not all will work but see how you go.

For status codes, see http://msdn.microsoft.com/en-us/library/aa383887(VS.85).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!