问题描述
这是一个很奇怪的问题,但我想测试自定义错误的例如web.config设置:
This is quite an odd question, but I am trying to test the Web.Config settings for custom errors e.g.:
<customErrors mode="On"/>
<error statusCode="500" redirect="500.html"/>
<error statusCode="500.13" redirect="500.13.html"/>
</customErrors>
反正我有可以创建一个页面或拦截在Global.asax请求的Application_BeginRequest
的方法,可以伪造一个响应发送到浏览器,即设置一个500.13 HTTP错误状态,它告诉IIS以使用在web.config中定义的 500.13.html
页
Is there anyway I can create a page or intercept the request in the global.asax Application_BeginRequest
method that can fake up a response to send to the browser i.e. setup a 500.13 HTTP error status which tells IIS to use the 500.13.html
page defined in the Web.Config.
在理想情况下,我想要做像创建一个网页,需要我想如返回的状态code的查询字符串值 FakeRequest.html?ErrorStatus中= 500.13
让我们的测试可以确保适当的页面返回的各种错误。
Ideally, I'd like to do something like create a page that takes a query string value of the status code I want returned e.g. FakeRequest.html?errorStatus=500.13
so that our testers can make sure the appropriate page is returned for the various errors.
推荐答案
尝试是这样的:
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");
}
}
这个发现在以下页面:
这篇关于在IIS / .NET测试伪装Http状态codeS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!