如何在IIS7.5上进行Response.Write? [英] How to Response.Write on IIS7.5?
问题描述
我正在尝试向客户写一个回复:
i am trying to write out a response to the client:
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(Professional(64-bit))))开发Cassini Web服务器上运行时,代码运行正常:
The code works fine when running on the localhost (Visual Studio (2010 (Windows 7 (Professional (64-bit))))) development Cassini web-server:
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时,相同的代码不起作用:
But when i deploy the web-site to Windows Server 2008 R2 running IIS7.5, the same code doesn't work:
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
如何从IIS执行Response.Write
?
推荐答案
默认情况下,如果代码> = 400,则IIS 7将更改响应. http://msdn.microsoft.com/en-us/library/ms690497 (v = vs.90).aspx
By default, IIS 7 will change the response if the code is >= 400 http://msdn.microsoft.com/en-us/library/ms690497(v=vs.90).aspx
但是您可以在system.webServer
的httpErrors
元素中进行更改.
But you can change this in the httpErrors
element of system.webServer
.
<httpErrors existingResponse="PassThrough" />
如果您正在使用CustomErrors
,它将破坏CustomErrors
.您最好返回无响应的400,然后将web.config设置为重定向到自定义页面,以免出现400个错误.
this will break CustomErrors
, if you are using that. You might be better off returning a 400 without a response, then setting up web.config to redirect to a custom page for 400 errors.
<customErrors mode="On">
<error statusCode="400" redirect="Frobber.htm" />
</customErrors>
这篇关于如何在IIS7.5上进行Response.Write?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!