ASP.NET页面POST只能访问

时间:2015-09-01 08:09:34

标签: asp.net ajax post get

我想知道是否可以将对ASPX页面的访问权限仅限于http POST请求方法?此受限页面将用于呈现一些复杂的内容。我想将它用于ajax调用,它会将该内容返回到另一个页面上的div中。是否可以禁用GET请求,以便用户无法通过浏览器中的URL偶然访问它?

1 个答案:

答案 0 :(得分:3)

您无法阻止用户发出GET请求。您可以在服务器上选择您无法提供服务的服务器。例如:

{"Unable to cast the type 'OfferManagementBackOffice.Placement' to type 'OfferManagementBackOffice.IGameId'. LINQ to Entities only supports casting EDM primitive or enumeration types."}

这可以在 if (!string.Equals(Request.HttpMethod, "POST")) { Response.StatusCode = 405; Response.End(); } 事件中实现,甚至可以在Page_Load中实现(如果您需要更多页面等)。