0

I have a server making a head request to a database dump I've created. The remote server does this to make sure that it's not using excessive bandwidth when not necessary.

However, due to some other circumstances outside my control this causes the script to be hit twice: once for the head request, and then another time to download the data.

What I'd like is to have the script I've written detect the head request, send back a couple of headers (e.g. last modified is right now, filesize different than before), and exit. Is there a way to do this?

4

1 回答 1

1

由于这仍然没有答案,我会试一试,即使我不怎么做 ASP.NET。

我只熟悉 ASP.NET MVC 3,所以这里有一些我用来响应 HEAD 请求的示例代码:

Function Index() As ActionResult
    ControllerContext.HttpContext.Response.AddHeader("NewHeader", "Value")

    Return View()
End Function

<ActionName("Index")>
<AcceptVerbs(HttpVerbs.Head)>
Function IndexHead() As ActionResult
    Return Index()
End Function

我不确定这是否仍然发送内容,但我没有在 Firefox(带有实时 HTTP 标头)或带有WebRequest. 可能只是那两个忽略了内容;不过,我无法用我的数据包嗅探器确认。

此外,如果您想对标头进行更多控制,则需要 IIS 7.0,如此MSDN 文章中所述。

于 2011-11-25T18:59:23.610 回答