租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

Response.AddHeader使用实例

发布时间:2023-09-15 12:30:26

Response.AddHeader使用实例

以下是Response.AddHeader方法的一个示例:
```
using System;
using System.Web;

namespace MyNamespace
{

public class MyHttpHandler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

HttpResponse response = context.Response;

// 添加一个自定义的响应头

response.AddHeader("MyCustomHeader", "Hello World!");

// 设置其他响应头

response.ContentType = "text/plain";

response.ContentLength = 12;

// 发送响应内容

response.Write("Hello World!");

}

public bool IsReusable

{

get { return false; }

}

}
}
```
在上面的示例中,我们使用了`response.AddHeader`方法来添加一个自定义的响应头,名为"MyCustomHeader",值为"Hello World!"。然后,我们设置了其他一些常见的响应头,如`response.ContentType`和`response.ContentLength`。最后,我们使用`response.Write`方法发送响应内容。请注意,这个示例是在ASP.NET Web利用程序中使用的,因此我们需要实现`IHttpHandler`接口来处理HTTP要求。