3
Asp.NET MVC 3中是否有一種方法以通用方式響應HEAD請求,而不是將HEAD屬性添加到單個方法中。達到或接近你的路由頂部對asp.NET MVC中的HEAD請求做出響應3
routes.MapRoute(
"HEAD Requests",
"{*fullPath}",
new { controller = "Head", action = "Index" },
new { fullPath = new MustBeHeadRequest() }
);
public class MustBeHeadRequest : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return httpContext.Request.HttpMethod.ToLowerInvariant() == "head";
}
}
地點的路線: