在我而言,我只是得到HEAD請求。所以,我有點擔心回到500或404。
更多關於405
405可按照的Albireo的回答OK,但你需要返回接受動詞,是這樣的:
// 405 must include allowable methods.
// https://tools.ietf.org/html/rfc2616#section-14.7
httpContext.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
httpContext.Response.AddHeader("Allow", "GET");
302選項
展望在未重定向HEAD請求的MVC代碼中註釋:
//only redirect for GET requests, otherwise the browser might not propagate the verb and request
//body correctly.
看起來另一種選擇是發送一個302.將一個302返回到HTTPS站點,以便將bot HEAD請求返回給根(這是MVC爲GET所做的)應該是合理安全的。所以,我實現它是基於MVC做它的方式如下:
if(isHead == true && isRoot == true)
{
httpContext.ClearError();
httpContext.Response.Clear();
httpContext.Response.StatusCode = 302;
string url = "https://" + httpContext.Request.Url.Host + httpContext.Request.RawUrl;
httpContext.Response.Redirect(url, endResponse: false);
return;
}
實現的global.asax.cs:
protected void Application_Error(object sender, EventArgs e)
{
//Your code here
}
500看起來不正確...是不是有這樣的狀態代碼? 500表明實際上有一處錯誤。 – 2011-12-15 17:18:30