我正在尝试写一个给客户的回复:
response.StatusCode = (int)HttpStatusCode.BadRequest;
response.ClearContent();
response.Write(String.Format(
"<!doctype html>"+CRLF+
"<html>" + CRLF +
"<head><title>{0}</title></head>" + CRLF +
"<body><h1>{0}</h1>"+CRLF+
"{1}"+CRLF+
"</body>" + CRLF +
"</html>",
response.Status, "The grob must be in the frobber."));
response.Flush();
response.End();
该代码在本地主机(Visual Studio(2010(Windows 7(专业版(64位)))))开发 Cassini Web 服务器上运行时工作正常:
HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/10.0.0.0
Date: Tue, 17 Jul 2012 15:56:42 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/html
Connection: Close
<!doctype html>
<html>
<head><title>400 Bad Request</title></head>
<body><h1>400 Bad Request</h1>
The grob must be in the frobber.
</body>
</html>
但是当我将网站部署到运行 IIS7.5 的 Windows Server 2008 R2 时,相同的代码不起作用:
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 17 Jul 2012 15:57:44 GMT
Content-Length: 11
Bad Request
我该如何表现Response.Write
来自 IIS?
默认情况下,如果代码 >= 400,IIS 7 将更改响应http://msdn.microsoft.com/en-us/library/ms690497(v=vs.90).aspx http://msdn.microsoft.com/en-us/library/ms690497(v=vs.90).aspx
但你可以在httpErrors
的元素system.webServer
.
<httpErrors existingResponse="PassThrough" />
编辑:这会打破CustomErrors
,如果你正在使用它。您最好返回没有响应的 400,然后设置 web.config 以重定向到 400 错误的自定义页面。
<customErrors mode="On">
<error statusCode="400" redirect="Frobber.htm" />
</customErrors>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)